public bool Delete(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (DueColorMngEntities context = CreateContext()) { DueColor dbItem = context.DueColor.FirstOrDefault(o => o.DueColorID == id); if (dbItem == null) { notification.Message = "MaterialColor not found!"; return(false); } else { context.DueColor.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool Update(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; DTO.DueColorDTO dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.DueColorDTO>(); try { using (var context = CreateContext()) { DueColor dueColor = null; if (id == 0) { dueColor = new DueColor(); context.DueColor.Add(dueColor); } else { dueColor = context.DueColor.FirstOrDefault(o => o.DueColorID == id); } if (dueColor == null) { notification.Message = "Due Color not found!"; return(false); } else { converter.DTO2BD_DueColor(dtoItems, ref dueColor); context.SaveChanges(); dtoItem = GetEditData(dueColor.DueColorID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD_DueColor(DTO.DueColorDTO dtoItem, ref DueColor dbItem) { AutoMapper.Mapper.Map <DTO.DueColorDTO, DueColor>(dtoItem, dbItem); }