public void DB2DTO_POD(DTO.POD dtoItem, ref POD dbItem) { AutoMapper.Mapper.Map <DTO.POD, POD>(dtoItem, dbItem); }
public bool UpdateData(int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { DTO.POD dtoPOD = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.POD>(); using (PODMngEntities context = CreateContext()) { POD dbItem = null; if (id == 0) { dbItem = new POD(); context.POD.Add(dbItem); } else { dbItem = context.POD.FirstOrDefault(o => o.PoDID == id); } if (dbItem == null) { notification.Message = "POD not found"; return(false); } else { converter.DB2DTO_POD(dtoPOD, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.PoDID, out notification).Data; return(true); } } } catch (System.Data.DataException dEx) { notification.Type = Library.DTO.NotificationType.Error; Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName); if (number == 2601 && !string.IsNullOrEmpty(indexName)) { if (indexName == "PoDUDUniqe") { notification.Message = "The POD Code is already exists"; } } else { notification.Message = dEx.Message; } return(false); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }