public override bool Approve(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (LedgerAccountMngEntities context = CreateContext()) { LedgerAccount dbItem = context.LedgerAccount.FirstOrDefault(o => o.LedgerAccountID == id); if (dbItem == null) { throw new Exception("Account not found !"); } LedgerAccountMng_LedgerAccountSearchResult_View currentData = context.LedgerAccountMng_LedgerAccountSearchResult_View.FirstOrDefault(o => o.LedgerAccountID == id); //LedgerAccount newData = new LedgerAccount(); dbItem.OpeningCredit = currentData.ClosingCredit; dbItem.OpeningDebit = currentData.ClosingDebit; //context.LedgerAccount.Add(newData); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.LedgerAccountID, out notification).Data; return(true); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.LedgerAccount dtoLedgerAccount = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.LedgerAccount>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (LedgerAccountMngEntities context = CreateContext()) { LedgerAccount dbItem = null; if (id == 0) { dbItem = new LedgerAccount(); context.LedgerAccount.Add(dbItem); } else { dbItem = context.LedgerAccount.FirstOrDefault(o => o.LedgerAccountID == id); } if (dbItem == null) { notification.Message = "Profile not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoLedgerAccount.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoLedgerAccount, ref dbItem); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.LedgerAccountID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool CloseEntry(int userId, object dtoItem, out Library.DTO.Notification notification) { //DTO.LedgerAccount dtoLedgerAccount = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject<DTO.LedgerAccount>(); List <DTO.LedgerAccount> dtoLedgerAccount = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.LedgerAccount> >(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { foreach (DTO.LedgerAccount dtoAccount in dtoLedgerAccount) { using (LedgerAccountMngEntities context = CreateContext()) { LedgerAccount dbItem = context.LedgerAccount.FirstOrDefault(o => o.LedgerAccountID == dtoAccount.LedgerAccountID); if (dbItem == null) { throw new Exception("Account not found !"); } if (dbItem.AccountNo != "911") { LedgerAccountMng_LedgerAccountSearchResult_View currentData = context.LedgerAccountMng_LedgerAccountSearchResult_View.FirstOrDefault(o => o.LedgerAccountID == dtoAccount.LedgerAccountID); dbItem.OpeningCredit = currentData.ClosingCredit; dbItem.OpeningDebit = currentData.ClosingDebit; dbItem.UpdatedDate = DateTime.Now; context.SaveChanges(); } } } return(true); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.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 (LedgerAccountMngEntities context = CreateContext()) { LedgerAccount dbItem = context.LedgerAccount.FirstOrDefault(o => o.LedgerAccountID == id); if (dbItem == null) { notification.Message = "Profile not found!"; return(false); } else { context.LedgerAccount.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(false); } }
public void DTO2BD(DTO.LedgerAccount dtoItem, ref LedgerAccount dbItem) { AutoMapper.Mapper.Map <DTO.LedgerAccount, LedgerAccount>(dtoItem, dbItem); dbItem.UpdatedDate = DateTime.Now; }