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 (AVFSupplierMngEntities context = CreateContext()) { AVFSupplier dbItem = context.AVFSupplier.FirstOrDefault(o => o.AVFSupplierID == id); if (dbItem == null) { throw new Exception("Supplier not found !"); } AVFSupplierMng_SupplierSearchResult_View currentData = context.AVFSupplierMng_SupplierSearchResult_View.FirstOrDefault(o => o.AVFSupplierID == 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.AVFSupplierID, 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.AVFSupplier dtoAVFSupplier = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.AVFSupplier>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (AVFSupplierMngEntities context = CreateContext()) { AVFSupplier dbItem = null; if (id == 0) { dbItem = new AVFSupplier(); context.AVFSupplier.Add(dbItem); } else { dbItem = context.AVFSupplier.FirstOrDefault(o => o.AVFSupplierID == id); } if (dbItem == null) { notification.Message = "Profile not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoAVFSupplier.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoAVFSupplier, ref dbItem); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.AVFSupplierID, 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.AVFSupplier dtoAVFSupplier = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject<DTO.AVFSupplier>(); List <DTO.AVFSupplier> dtoAVFSupplier = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.AVFSupplier> >(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { foreach (DTO.AVFSupplier dtoSupplier in dtoAVFSupplier) { using (AVFSupplierMngEntities context = CreateContext()) { AVFSupplier dbItem = context.AVFSupplier.FirstOrDefault(o => o.AVFSupplierID == dtoSupplier.AVFSupplierID); if (dbItem == null) { throw new Exception("Supplier not found !"); } AVFSupplierMng_SupplierSearchResult_View currentData = context.AVFSupplierMng_SupplierSearchResult_View.FirstOrDefault(o => o.AVFSupplierID == dtoSupplier.AVFSupplierID); 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 (AVFSupplierMngEntities context = CreateContext()) { AVFSupplier dbItem = context.AVFSupplier.FirstOrDefault(o => o.AVFSupplierID == id); if (dbItem == null) { notification.Message = "Profile not found!"; return(false); } else { context.AVFSupplier.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); } }