예제 #1
0
        public override bool Approve(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.FactoryPayment2BalanceDTO dtoBalance = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryPayment2BalanceDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check permission
                if (fwFactory.CheckDPBalancePermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected balance data");
                }

                using (FactoryPayment2BalanceMngEntities context = CreateContext())
                {
                    FactoryPayment2Balance dbItem = context.FactoryPayment2Balance.FirstOrDefault(o => o.FactoryPayment2BalanceID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("DP balance not found!");
                    }

                    // validate before approve
                    // add next season balance
                    FactoryPayment2BalanceMng_FactoryPayment2BalanceSearchResult_View balanceSummary = context.FactoryPayment2BalanceMng_FactoryPayment2BalanceSearchResult_View.FirstOrDefault(o => o.FactoryPayment2BalanceID == id);
                    FactoryPayment2Balance newBalance = new FactoryPayment2Balance();
                    newBalance.SupplierID   = dbItem.SupplierID;
                    newBalance.Season       = Library.OMSHelper.Helper.GetNextSeason(dbItem.Season);
                    newBalance.BeginBalance = balanceSummary.EndBalance;
                    newBalance.UpdatedDate  = DateTime.Now;
                    newBalance.UpdatedBy    = userId;
                    context.FactoryPayment2Balance.Add(newBalance);

                    dbItem.isClosed    = true;
                    dbItem.UpdatedDate = DateTime.Now;
                    dbItem.UpdatedBy   = userId;
                    context.SaveChanges();
                    dtoItem = GetData(userId, dbItem.FactoryPayment2BalanceID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
예제 #2
0
        public override bool Reset(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.FactoryPayment2BalanceDTO dtoBalance = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryPayment2BalanceDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check permission
                if (fwFactory.CheckDPBalancePermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected balance data");
                }

                using (FactoryPayment2BalanceMngEntities context = CreateContext())
                {
                    FactoryPayment2Balance dbItem = context.FactoryPayment2Balance.FirstOrDefault(o => o.FactoryPayment2BalanceID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("DP balance not found!");
                    }

                    // validate before reset


                    dbItem.isClosed    = null;
                    dbItem.UpdatedDate = null;
                    dbItem.UpdatedBy   = null;
                    context.SaveChanges();
                    dtoItem = GetData(userId, dbItem.FactoryPayment2BalanceID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }