public IHttpActionResult Update(int id, DTO.DDCMng.DDC dtoItem) { Library.DTO.Notification notification; // authentication Module.Framework.BLL fwBll = new Module.Framework.BLL(); if (id > 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanUpdate)) { // edit case return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } else if (id == 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanCreate)) { // create new case return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } // validation if (!Helper.CommonHelper.ValidateDTO <DTO.DDCMng.DDC>(dtoItem, out notification)) { return(Ok(new Library.DTO.ReturnData <DTO.DDCMng.DDC>() { Data = dtoItem, Message = notification })); } // continue processing BLL.DDCMng bll = new BLL.DDCMng(); bll.UpdateData(id, ref dtoItem, ControllerContext.GetAuthUserId(), out notification); return(Ok(new Library.DTO.ReturnData <DTO.DDCMng.DDC>() { Data = dtoItem, Message = notification })); }
public void DTO2BD(DTO.DDCMng.DDC dtoItem, ref DDC dbItem) { AutoMapper.Mapper.Map <DTO.DDCMng.DDC, DDC>(dtoItem, dbItem); // map load ddc detail if (dtoItem.Details != null) { // check for child rows deleted foreach (DDCDetail dbDetail in dbItem.DDCDetail.ToArray()) { if (!dtoItem.Details.Select(o => o.DDCDetailID).Contains(dbDetail.DDCDetailID)) { dbItem.DDCDetail.Remove(dbDetail); } } // map child rows foreach (DTO.DDCMng.DDCDetail dtoDetail in dtoItem.Details) { DDCDetail dbDetail; if (dtoDetail.DDCDetailID <= 0) { dbDetail = new DDCDetail(); dbItem.DDCDetail.Add(dbDetail); } else { dbDetail = dbItem.DDCDetail.FirstOrDefault(o => o.DDCDetailID == dtoDetail.DDCDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.DDCMng.DDCDetail, DDCDetail>(dtoDetail, dbDetail); } } } }