public void DTO2DB_BifaTelephone(int userID, DTO.BifaTelephone dtoItem, ref BifaTelephone dbItem) { AutoMapper.Mapper.Map <DTO.BifaTelephone, BifaTelephone>(dtoItem, dbItem); dbItem.BifaCompanyID = dtoItem.BifaCompanyID; dbItem.UpdatedBy = userID; dbItem.UpdatedDate = System.DateTime.Now; }
public object UpdateTelephone(int userID, int id, System.Collections.Hashtable filters, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification(); notification.Type = Library.DTO.NotificationType.Success; DTO.BifaTelephone dtoItem = ((Newtonsoft.Json.Linq.JObject)filters["view"]).ToObject <DTO.BifaTelephone>(); try { using (var context = CreateContext()) { BifaTelephone dbItem; if (id == 0) { dbItem = new BifaTelephone(); context.BifaTelephone.Add(dbItem); } else { dbItem = context.BifaTelephone.FirstOrDefault(o => o.BifaTelephoneID == id); } if (dbItem == null) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = "Can not find bifa telephone!"; } else { converter.DTO2DB_BifaTelephone(userID, dtoItem, ref dbItem); context.SaveChanges(); dtoItem = AutoMapper.Mapper.Map <BifaCompanyMng_BifaTelephone_View, DTO.BifaTelephone>(context.BifaCompanyMng_BifaTelephone_View.FirstOrDefault(o => o.BifaTelephoneID == dbItem.BifaTelephoneID)); } } } catch (System.Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Helper.GetInnerException(ex).Message; } return(dtoItem); }