public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.LeaveRequest dtoLeaveRequest = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.LeaveRequest>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (LeaveRequestMngEntities context = CreateContext()) { LeaveRequest dbItem = null; if (id == 0) { dbItem = new LeaveRequest(); context.LeaveRequest.Add(dbItem); } else { dbItem = context.LeaveRequest.FirstOrDefault(o => o.LeaveRequestID == id); } if (dbItem == null) { notification.Message = "LeaveRequest not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoLeaveRequest.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoLeaveRequest, ref dbItem); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.LeaveRequestID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD(DTO.LeaveRequest dtoItem, ref LeaveRequest dbItem) { dbItem.FromDate = dtoItem.FromDate.ConvertStringToDateTime(); dbItem.ToDate = dtoItem.ToDate.ConvertStringToDateTime(); AutoMapper.Mapper.Map <DTO.LeaveRequest, LeaveRequest>(dtoItem, dbItem); }