public override bool UpdateData(int id, ref DTO.ConstantEntryMng.ConstantEntry dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (ConstantEntryMngEntities context = CreateContext()) { ConstantEntry dbItem = null; if (id == 0) { dbItem = new ConstantEntry(); context.ConstantEntry.Add(dbItem); } else { dbItem = context.ConstantEntry.FirstOrDefault(o => o.ConstantEntryID == id); } if (dbItem == null) { notification.Message = "ConstantEntry not found!"; return(false); } else { converter.DTO2BD_ConstantEntry(dtoItem, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.ConstantEntryID, 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 == "DisplayTextUnique") { notification.Message = "Display Text already exists"; } } else { notification.Message = dEx.Message; } return(false); } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ConstantEntryMngEntities context = CreateContext()) { ConstantEntry dbItem = context.ConstantEntry.FirstOrDefault(o => o.ConstantEntryID == id); if (dbItem == null) { notification.Message = "ConstantEntry not found!"; return(false); } else { context.ConstantEntry.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD_ConstantEntry(DTO.ConstantEntryMng.ConstantEntry dtoItem, ref ConstantEntry dbItem) { AutoMapper.Mapper.Map <DTO.ConstantEntryMng.ConstantEntry, ConstantEntry>(dtoItem, dbItem); }