Exemplo n.º 1
0
 public void DTO2DB(DTO.UserProfile dtoItem, ref Employee dbItem, string TmpFile, int userId)
 {
     // employee
     AutoMapper.Mapper.Map <DTO.UserProfile, Employee>(dtoItem, dbItem);
     if (!string.IsNullOrEmpty(dtoItem.DateOfBirth))
     {
         if (DateTime.TryParse(dtoItem.DateOfBirth, nl, System.Globalization.DateTimeStyles.None, out tmpDate))
         {
             dbItem.DateOfBirth = tmpDate;
         }
     }
     if (!string.IsNullOrEmpty(dtoItem.DateStart))
     {
         if (DateTime.TryParse(dtoItem.DateStart, nl, System.Globalization.DateTimeStyles.None, out tmpDate))
         {
             dbItem.DateStart = tmpDate;
         }
     }
     if (dtoItem.HasChanged)
     {
         dbItem.PersonalPhoto = fwFactory.CreateFilePointer(TmpFile, dtoItem.NewFile, dbItem.PersonalPhoto);
     }
     if (dtoItem.CVHasChanged)
     {
         dbItem.ResumeFile = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.CVNewFile, dbItem.ResumeFile, dtoItem.CVFileName);
     }
     foreach (DTO.EmployeeFactory dtoFactory in dtoItem.EmployeeFactories)
     {
         EmployeeFactory dbFactory = dbItem.EmployeeFactory.FirstOrDefault(o => o.EmployeeFactoryID == dtoFactory.EmployeeFactoryID);
         AutoMapper.Mapper.Map <DTO.EmployeeFactory, EmployeeFactory>(dtoFactory, dbFactory);
     }
 }
Exemplo n.º 2
0
        public bool UpdateEmployee(int userId, int id, object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.UserProfile dtoProfile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.UserProfile>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (User2MngEntities context = CreateContext())
                {
                    Employee dbItem = context.Employee.FirstOrDefault(o => o.EmployeeID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Employee not found!");
                    }
                    dbItem.UpdatedBy   = userId;
                    dbItem.UpdatedDate = DateTime.Now;
                    converter.DTO2DB(dtoProfile, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId);
                    dbItem.EmployeeFactory.ToList().ForEach(o => context.EmployeeFactory.Remove(o));
                    foreach (DTO.EmployeeFactory dtoFactory in dtoProfile.EmployeeFactories)
                    {
                        EmployeeFactory dbFactory = new EmployeeFactory();
                        dbItem.EmployeeFactory.Add(dbFactory);
                        dbFactory.FactoryID = dtoFactory.FactoryID;
                    }
                    context.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }