Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }