public async Task Add(string referenceCode, ServiceTypes serviceType, MoneyAmount convertedSupplierPrice, MoneyAmount originalSupplierPrice, Deadline deadline, int supplier, SupplierPaymentType paymentType, DateTime paymentDate) { var now = _dateTimeProvider.UtcNow(); var supplierOrder = new SupplierOrder { Created = now, Modified = now, ConvertedPrice = convertedSupplierPrice.Amount, ConvertedCurrency = convertedSupplierPrice.Currency, Price = originalSupplierPrice.Amount, Currency = originalSupplierPrice.Currency, RefundableAmount = 0, State = SupplierOrderState.Created, Supplier = supplier, Type = serviceType, ReferenceCode = referenceCode, Deadline = deadline, PaymentDate = paymentDate, PaymentType = paymentType }; _context.SupplierOrders.Add(supplierOrder); await _context.SaveChangesAsync(); _context.Detach(supplierOrder); }
public IHttpActionResult UpdateSupplierPaymentDetails(SupplierPaymentTypeViewModels supplierPaymentType) { try { string errorMessege = string.Empty; if (ModelState.IsValid) { SupplierPaymentType entity = new SupplierPaymentType(); entity.AccountName = supplierPaymentType.accountName; entity.AccountNumber = supplierPaymentType.accountNumber; entity.Bank.Name = supplierPaymentType.bankName; entity.BankId = supplierPaymentType.bankId; entity.Branch = supplierPaymentType.branch; entity.Id = supplierPaymentType.id; entity.IsActive = supplierPaymentType.isActive; entity.PayementType = supplierPaymentType.payementType; entity.PaymentTypeId = supplierPaymentType.paymentTypeId; entity.Supplier = supplierPaymentType.supplier; entity.SupplierId = supplierPaymentType.supplierId; List <string> properties = new List <string>(); properties.Add("AccountName"); properties.Add("AccountNumber"); properties.Add("Bank.Name"); properties.Add("Branch"); _supplierPaymentType.UpdateSupplierPaymentDetails(entity, 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)); } }
public IHttpActionResult CreateSuppliers(SupplierFormViewModel supplier) { try { string errorMessege = string.Empty; if (ModelState.IsValid) { Supplier entity = new Supplier(); entity.Address = supplier.address; entity.ContactNo = supplier.contactNumber; entity.FullName = supplier.fullName; entity.IsActive = supplier.isActive; entity.LeafTypeId = supplier.leafTypes.id; entity.NICNo = supplier.nicNo; entity.Notes = supplier.notes; entity.RegNo = supplier.registrationNo; entity.RouteId = supplier.routes.id; entity.SupplierTypeId = supplier.types.id; entity.CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); entity.CreatedBy = "admin";//User.Identity.Name; entity.ModifiedBy = "admin"; entity.ModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); SupplierPaymentType supplierPaymentType = new SupplierPaymentType(); supplierPaymentType.SupplierId = entity.Id; supplierPaymentType.PaymentTypeId = supplier.supplierPaymentTypes.paymentModes.id; supplierPaymentType.AccountName = supplier.supplierPaymentTypes.accountName; supplierPaymentType.AccountNumber = supplier.supplierPaymentTypes.accountNumber; supplierPaymentType.BankId = supplier.supplierPaymentTypes.banks.id; supplierPaymentType.Branch = supplier.supplierPaymentTypes.branch; entity.SupplierPaymentTypes.Add(supplierPaymentType); foreach (SupplierFundViewModel fundsVm in supplier.supplierFunds) { SupplierFund supplierFund = new SupplierFund(); supplierFund.SupplierId = entity.Id; supplierFund.Amount = fundsVm.fundAmount; supplierFund.FundId = fundsVm.fundNames.id; supplierFund.FundModeId = fundsVm.fundModes.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"])); entity.SupplierFunds.Add(supplierFund); } _supplier.Add(entity, 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()); } }
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; } }