예제 #1
0
 public IHttpActionResult UpdateSupplierFinancialDetails(UpdateSupplierFinancialDetailsViewModel supplier)
 {
     try
     {
         string errorMessege = string.Empty;
         if (ModelState.IsValid)
         {
             List <string> properties = new List <string>();
             properties.Add("AccountNumber");
             properties.Add("AccountName");
             properties.Add("Branch");
             properties.Add("BankId");
             properties.Add("PaymentTypeId");
             _supplier.UpdateSupplierFinanceDetails(supplier, properties, true, out errorMessege);
         }
         else
         {
             errorMessege = ReadOnlyValue.GeneralError;
         }
         var messageData = new
         {
             code    = String.IsNullOrEmpty(errorMessege) ? ReadOnlyValue.SuccessMessageCode : ReadOnlyValue.ErrorMessageCode,
             message = String.IsNullOrEmpty(errorMessege) ? ReadOnlyValue.MessageSuccess : errorMessege
         };
         var returnObject = new { messageCode = messageData };
         return(Ok(returnObject));
     }
     catch (Exception ex)
     {
         string errorLogId   = _eventLogService.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
         var    messageData  = new { code = ReadOnlyValue.ErrorMessageCode, message = String.Format(ReadOnlyValue.MessageTaskmateError, errorLogId) };
         var    returnObject = new { messageCode = messageData };
         return(Ok(returnObject));
     }
 }
예제 #2
0
        public virtual void UpdateSupplierFinanceDetails(UpdateSupplierFinancialDetailsViewModel entity, List <string> properties, bool isIncluded, out string errorMessege)
        {
            try
            {
                using (var dbContextTransaction = _supplierPaymentTypeRepository.DbContext.Database.BeginTransaction())
                {
                    try
                    {
                        //Supplier supplier = new Supplier();
                        //supplier = _supplierRepository.Get(x => x.Id == entity.id).FirstOrDefault();

                        SupplierPaymentType supplierPaymentType = new SupplierPaymentType();
                        supplierPaymentType = _supplierPaymentTypeRepository.Get(o => o.SupplierId == entity.id).FirstOrDefault();// supplier.SupplierPaymentTypes.Where(x => x.SupplierId == entity.id).FirstOrDefault();

                        supplierPaymentType.AccountNumber = entity.accountNumber;
                        supplierPaymentType.AccountName   = entity.accountName;
                        supplierPaymentType.Branch        = entity.branch;
                        supplierPaymentType.BankId        = entity.banks.id;
                        supplierPaymentType.PaymentTypeId = entity.paymentModes.id;

                        _supplierPaymentTypeRepository.Update(supplierPaymentType, properties, true);


                        properties.Clear();
                        properties.Add("FundModeId");
                        properties.Add("FundId");
                        properties.Add("Amount");
                        properties.Add("ModifiedDate");
                        properties.Add("ModifiedBy");

                        foreach (SupplierFundViewModel item in entity.supplierFunds)
                        {
                            if (item.supplierFundId != 0) //make this !=0 after sending the supplierFundId from the front end
                            {
                                SupplierFund supplierFund = new SupplierFund();
                                supplierFund              = _supplierFundsRepository.Get(x => x.Id == item.supplierFundId).FirstOrDefault(); // 28 should be item.id -- and SupplierFundViewModel's id should be the supplierFundId
                                supplierFund.FundModeId   = item.fundModes.id;
                                supplierFund.FundId       = item.fundNames.id;
                                supplierFund.Amount       = item.fundAmount;
                                supplierFund.CreatedDate  = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]));
                                supplierFund.CreatedBy    = "admin";//User.Identity.Name;
                                supplierFund.ModifiedBy   = "admin";
                                supplierFund.ModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]));

                                _supplierFundsRepository.Update(supplierFund, properties, true);
                            }
                            else
                            {
                                SupplierFund supplierFund = new SupplierFund();
                                supplierFund.FundModeId   = item.fundModes.id;
                                supplierFund.FundId       = item.fundNames.id;
                                supplierFund.Amount       = item.fundAmount;
                                supplierFund.SupplierId   = entity.id;
                                supplierFund.CreatedDate  = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]));
                                supplierFund.CreatedBy    = "admin";//User.Identity.Name;
                                supplierFund.ModifiedBy   = "admin";
                                supplierFund.ModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]));

                                _supplierFundsRepository.Add(supplierFund);
                            }
                        }
                        errorMessege = String.Empty;
                        _unitOfWork.Commit();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
                errorMessege = String.Empty;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }