public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { DTO.CheckListDTO checkListDTO = ((JObject)dtoItem).ToObject <DTO.CheckListDTO>(); notification = new Notification { Type = NotificationType.Success }; try { using (var context = CreateContext()) { CheckList checkList = new CheckList(); if (id == 0) { context.CheckList.Add(checkList); } if (id > 0) { checkList = context.CheckList.FirstOrDefault(o => o.CheckListID == id); if (checkList == null) { notification = new Notification { Type = NotificationType.Error, Message = "Can't Find Data" }; return(false); } } this.converter.DTO2DB_CheckList(checkListDTO, ref checkList); context.SaveChanges(); dtoItem = this.GetData(checkList.CheckListID, out notification); } return(true); } catch (Exception ex) { notification = new Notification { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
public void DTO2DB_CheckList(DTO.CheckListDTO dto, ref CheckList db) { AutoMapper.Mapper.Map <DTO.CheckListDTO, CheckList>(dto, db); }