public void DTO2DB_BifaCompany(DTO.BifaCompany dtoItem, ref BifaCompany dbItem) { AutoMapper.Mapper.Map <DTO.BifaCompany, BifaCompany>(dtoItem, dbItem); dbItem.FoundingDate = dtoItem.FoundingDate.ConvertStringToDateTime(); dbItem.JoinedDate = dtoItem.JoinedDate.ConvertStringToDateTime(); }
public bool UpdateData(int userID, int id, ref object viewItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification(); notification.Type = Library.DTO.NotificationType.Success; DTO.BifaCompany dtoItem = ((Newtonsoft.Json.Linq.JObject)viewItem).ToObject <DTO.BifaCompany>(); try { BifaCompany dbItem; using (var context = CreateContext()) { if (id == 0) { dbItem = new BifaCompany(); context.BifaCompany.Add(dbItem); } else { dbItem = context.BifaCompany.FirstOrDefault(o => o.BifaCompanyID == id); } if (dbItem == null) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = "Can not find Bifa company!"; return(false); } else { // Process upload logo Bifa company Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory(); if (dtoItem.Logo_HasChange) { if (string.IsNullOrEmpty(dtoItem.Logo_NewFile)) { fwFactory.RemoveImageFile(dtoItem.Logo); } else { dtoItem.Logo = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userID.ToString() + @"\", dtoItem.Logo_NewFile, dtoItem.Logo); } } converter.DTO2DB_BifaCompany(dtoItem, ref dbItem); dbItem.UpdatedBy = userID; dbItem.UpdatedDate = System.DateTime.Now; context.SaveChanges(); viewItem = GetData(dbItem.BifaCompanyID, out notification); return(true); } } } catch (System.Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Helper.GetInnerException(ex).Message; return(false); } }