本文整理汇总了C#中Employee.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Employee.Save方法的具体用法?C# Employee.Save怎么用?C# Employee.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Employee
的用法示例。
在下文中一共展示了Employee.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RelationsOneToOne
public void RelationsOneToOne()
{
using (new SessionScope()) {
var emp = new Employee {FirstName = "john", LastName = "doe"};
emp.Save();
Assert.AreEqual(1, Employee.FindAll().Count());
var award = new Award(emp) {Description = "Invisible employee"};
award.Save();
emp.Award = award;
emp.Save();
Assert.AreEqual(1, Award.FindAll().Count());
var emp2 = Employee.Find(emp.Id);
Assert.IsNotNull(emp2);
Assert.IsNotNull(emp2.Award);
Assert.AreEqual(emp.FirstName, emp2.FirstName);
Assert.AreEqual(emp.LastName, emp2.LastName);
Assert.AreEqual(award.Description, emp2.Award.Description);
}
}
示例2: RelationsOneToOne
public void RelationsOneToOne()
{
Employee emp = new Employee();
emp.FirstName = "john";
emp.LastName = "doe";
emp.Save();
Assert.AreEqual(1, Employee.FindAll().Length);
Award award = new Award(emp);
award.Description = "Invisible employee";
award.Save();
Assert.AreEqual(1, Award.FindAll().Length);
Employee emp2 = Employee.Find(emp.ID);
Assert.IsNotNull(emp2);
Assert.IsNotNull(emp2.Award);
Assert.AreEqual(emp.FirstName, emp2.FirstName);
Assert.AreEqual(emp.LastName, emp2.LastName);
Assert.AreEqual(award.Description, emp2.Award.Description);
}
示例3: Insert
public void Insert(string LastName,string FirstName,string Title,string TitleOfCourtesy,DateTime? BirthDate,DateTime? HireDate,string Address,string City,string Region,string PostalCode,string Country,string HomePhone,string Extension,string Photo,string Notes,int? ReportsTo,string PhotoPath,bool Deleted)
{
Employee item = new Employee();
item.LastName = LastName;
item.FirstName = FirstName;
item.Title = Title;
item.TitleOfCourtesy = TitleOfCourtesy;
item.BirthDate = BirthDate;
item.HireDate = HireDate;
item.Address = Address;
item.City = City;
item.Region = Region;
item.PostalCode = PostalCode;
item.Country = Country;
item.HomePhone = HomePhone;
item.Extension = Extension;
item.Photo = Photo;
item.Notes = Notes;
item.ReportsTo = ReportsTo;
item.PhotoPath = PhotoPath;
item.Deleted = Deleted;
item.Save(UserName);
}
示例4: SaveToDb
//数据持久化
internal static void SaveToDb(EmployeeInfo pEmployeeInfo, Employee pEmployee,bool pIsNew)
{
pEmployee.EmployeeId = pEmployeeInfo.employeeId;
pEmployee.ContactId = pEmployeeInfo.contactId;
pEmployee.EmployeeName = pEmployeeInfo.employeeName;
pEmployee.PositionId = pEmployeeInfo.positionId;
pEmployee.Sex = pEmployeeInfo.sex;
pEmployee.Birthday = pEmployeeInfo.birthday;
pEmployee.Marrage = pEmployeeInfo.marrage;
pEmployee.Address = pEmployeeInfo.address;
pEmployee.NativePlace = pEmployeeInfo.nativePlace;
pEmployee.PoliticsId = pEmployeeInfo.politicsId;
pEmployee.IdentyNum = pEmployeeInfo.identyNum;
pEmployee.School = pEmployeeInfo.school;
pEmployee.Major = pEmployeeInfo.major;
pEmployee.EducationId = pEmployeeInfo.educationId;
pEmployee.LanguageId = pEmployeeInfo.languageId;
pEmployee.Certificate = pEmployeeInfo.certificate;
pEmployee.JobTime = pEmployeeInfo.jobTime;
pEmployee.JoinTime = pEmployeeInfo.joinTime;
pEmployee.DepartId = pEmployeeInfo.departId;
pEmployee.State = pEmployeeInfo.state;
pEmployee.OffJobTime = pEmployeeInfo.offJobTime;
pEmployee.Image = pEmployeeInfo.image;
pEmployee.Qq = pEmployeeInfo.qq;
pEmployee.TurnTime = pEmployeeInfo.turnTime;
pEmployee.EmLevelId = pEmployeeInfo.emLevelId;
pEmployee.EmDangId = pEmployeeInfo.emDangId;
pEmployee.IsNew=pIsNew;
string UserName = SubsonicHelper.GetUserName();
try
{
pEmployee.Save(UserName);
}
catch(Exception ex)
{
LogManager.getInstance().getLogger(typeof(EmployeeInfo)).Error(ex);
if(ex.Message.Contains("插入重复键"))//违反了唯一键
{
throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
}
throw new AppException("保存失败");
}
pEmployeeInfo.employeeId = pEmployee.EmployeeId;
//如果缓存存在,更新缓存
if (CachedEntityCommander.IsTypeRegistered(typeof(EmployeeInfo)))
{
ResetCache();
}
}
示例5: TranslateValuesForEmployee
public void TranslateValuesForEmployee(Employee employee, FieldLegalValueConfiguration fieldLegalValueConfiguration, string[] propertiesForEmployee, out TranslationLogEntry logEntry)
{
logEntry = null;
if (propertiesForEmployee == null)
{
propertiesForEmployee = Utilities.GetPropertyNames<Employee>();
}
// Loop through all fields for type
foreach (string fieldName in propertiesForEmployee)
{
string fieldValue = Convert.ToString(employee.GetMemberValue(fieldName));
IEnumerable<FieldLegalValue> legalValuesForFieldName = fieldLegalValueConfiguration.FieldLegalValuesForFieldName(fieldName);
if (String.IsNullOrEmpty(fieldValue) == false)
{
if (legalValuesForFieldName.Any(v => v.LegalValue == fieldValue) == true || legalValuesForFieldName.Count() == 0) // Check if legal
{
}
else
{
PropertyInfo propertyInfo = employee.GetType().GetProperty(fieldName);
FieldTranslatorChange change = new FieldTranslatorChange();
change.FieldName = fieldName;
change.PreviousValue = employee.GetMemberValue(fieldName);
bool logChange = true;
if (legalValuesForFieldName.Any(v => v.FieldTranslations.Cast<FieldTranslation>().Any(t => t.TranslationValue == fieldValue))) // If not legal - check if it can be autocorrected
{
object newValue = null;
var legalValueMatch = legalValuesForFieldName.Where(v => v.FieldTranslations.Cast<FieldTranslation>().Any(t => t.TranslationValue == fieldValue)).FirstOrDefault();
if (legalValueMatch != null)
{
newValue = legalValueMatch.LegalValue;
}
employee.SetMemberValue(fieldName, Convert.ChangeType(newValue, propertyInfo.PropertyType));
change.NewValue = Convert.ChangeType(newValue, propertyInfo.PropertyType);
change.Status = FieldTranslatorChangeStatus.Changed;
}
else // If it cannot be autocorrected
{
if (legalValuesForFieldName.All(x => x.DisallowOtherValues == false) == true) // Ignore if if it will allow other values than the ones defined as a legal value
{
logChange = false;
}
// Else Use the following behaviour
else if (Behaviour == FieldTranslatorBehaviour.KeepNonLegalValues)
{
change.Status = FieldTranslatorChangeStatus.Ignored;
}
else if (Behaviour == FieldTranslatorBehaviour.RemoveNonLegalValues)
{
employee.SetMemberValue(fieldName, Convert.ChangeType(null, propertyInfo.PropertyType));
change.Status = FieldTranslatorChangeStatus.Removed;
}
}
if (this.CommitChanges == true)
{
employee.Save();
}
if (logChange)
{
change.Employee = employee;
Changes.Add(change);
}
if (this.CommitChanges == true && change.Status != FieldTranslatorChangeStatus.Ignored && change.Status != FieldTranslatorChangeStatus.None)
{
Customer currentCustomer = CustomerUtilities.CurrentCustomerFromSession(employee.Session);
logEntry = new TranslationLogEntry(employee.Session)
{
PreviousValue = Convert.ToString(change.PreviousValue),
FieldName = fieldName,
NewValue = Convert.ToString(change.NewValue),
Employee = employee,
ChangeStatus = Convert.ToInt32(change.Status),
Customer = currentCustomer
};
logEntry.Save();
}
}
}
}
}