public async Task <bool> AddUpdateBidAndTender(cor_bid_and_tender model) { try { if (model.BidAndTenderId > 0) { var itemToUpdate = await _dataContext.cor_bid_and_tender.FindAsync(model.BidAndTenderId); _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model); } else { await _dataContext.cor_bid_and_tender.AddAsync(model); } if (model.Paymentterms != null) { if (model.Paymentterms.Count() > 0) { foreach (var item in model.Paymentterms.ToList()) { await AddUpdatePaymentTermsAsync(item); } } } return(await _dataContext.SaveChangesAsync() > 0); } catch (Exception ex) { throw ex; } }
public purch_plpo BuildThisBidLPO(purch_plpo thisBidLpo, cor_bid_and_tender currentBid) { try { var TaxSetup = _supRepo.GetTaxSetupSupplierTypeWithAsync(currentBid.SupplierId).Result; var supplier = _supRepo.GetSupplierAsync(currentBid.SupplierId).Result; var amount = _dataContext.cor_paymentterms.Where(e => e.BidAndTenderId == currentBid.BidAndTenderId && e.ProposedBy == (int)Proposer.STAFF).Sum(q => q.Amount); if (supplier != null) { var supplierType = _supRepo.GetSupplierTypeAsync(supplier.SupplierTypeId).Result; thisBidLpo.JobStatus = (int)JobProgressStatus.Not_Started; thisBidLpo.BidComplete = true; thisBidLpo.Name = supplier.Name; thisBidLpo.SupplierAddress = currentBid.Location; thisBidLpo.GrossAmount = currentBid.Total; thisBidLpo.BidAndTenderId = currentBid.BidAndTenderId; thisBidLpo.Description = currentBid.DescriptionOfRequest; thisBidLpo.WinnerSupplierId = currentBid.SupplierId; thisBidLpo.Total = currentBid.Total; thisBidLpo.ApprovalStatusId = (int)ApprovalStatus.Pending; thisBidLpo.Location = currentBid.Location; thisBidLpo.Quantity = currentBid.Quantity; thisBidLpo.AmountPayable = amount; thisBidLpo.CompanyId = currentBid.CompanyId; thisBidLpo.SupplierAddress = supplier.Address; thisBidLpo.SupplierNumber = supplier.SupplierNumber; thisBidLpo.Description = currentBid.DescriptionOfRequest; } if (TaxSetup.Count() > 0) { decimal charge = new decimal(); decimal deduction = new decimal(); thisBidLpo.Taxes = string.Join(',', TaxSetup.Select(s => s.TaxSetupId)); foreach (var tax in TaxSetup) { if (tax.Type == "+") { // (80 / 100) * 25 charge = thisBidLpo.GrossAmount / 100 * Convert.ToDecimal(tax.Percentage) + charge; } if (tax.Type == "-") { deduction = thisBidLpo.GrossAmount / 100 * Convert.ToDecimal(tax.Percentage) + deduction; } } thisBidLpo.AmountPayable = thisBidLpo.GrossAmount - deduction + charge; thisBidLpo.Tax = (thisBidLpo.AmountPayable - thisBidLpo.GrossAmount); } return(thisBidLpo); } catch (Exception ex) { throw; } }
private StaffApprovalRegRespObj Validation(cor_bid_and_tender item) { //if(item.DecisionResult == (int)DecisionResult.Lost) //{ // return new StaffApprovalRegRespObj // s // Status = new APIResponseStatus // { // IsSuccessful = false, // Message = new APIResponseMessage // { // FriendlyMessage = "Already lost the bid" // } // } // }; //} if (item.DecisionResult == (int)DecisionResult.Win) { return(new StaffApprovalRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Bid Already Approved" } } }); } return(new StaffApprovalRegRespObj { Status = new APIResponseStatus { IsSuccessful = true, } }); }
public async Task <BidAndTenderRegRespObj> Handle(AddUpdateBidAndTenderByStaffCommand request, CancellationToken cancellationToken) { var response = new BidAndTenderRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { var user = await _serverRequest.UserDataAsync(); if (user == null) { response.Status.Message.FriendlyMessage = "Unable To Process This User"; return(response); } cor_bid_and_tender bidAndTenderObj = new cor_bid_and_tender(); var supplierAdvert = _dataContext.cor_bid_and_tender.FirstOrDefault(q => q.SupplierId == request.SupplierId && q.LPOnumber.Trim().ToLower() == request.LPONumber.Trim().ToLower()); using (var trans = _dataContext.Database.BeginTransaction()) { try { if (supplierAdvert != null) { request.SupplierId = supplierAdvert.SupplierId; request.BidAndTenderId = supplierAdvert.BidAndTenderId; bidAndTenderObj = BuildBidAndTenderObject(request); await _repo.AddUpdateBidAndTender(bidAndTenderObj); } else { bidAndTenderObj = BuildBidAndTenderObject(request); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { trans.Dispose(); } } response.Status.IsSuccessful = true; response.BidAndTenderId = request.BidAndTenderId; response.Status.Message.FriendlyMessage = "Successful"; return(response); } catch (Exception ex) { #region Log error to file var errorCode = ErrorID.Generate(4); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new BidAndTenderRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error occured!! Unable to process item", MessageId = errorCode, TechnicalMessage = $"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}" } } }); #endregion } }
public async Task <BidAndTenderRegRespObj> Handle(UploadProposalCommand request, CancellationToken cancellationToken) { var response = new BidAndTenderRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { var user = await _serverRequest.UserDataAsync(); if (user == null) { response.Status.Message.FriendlyMessage = "Unable To Process This User"; return(response); } if (string.IsNullOrEmpty(request.LPONumber) || request.SupplierId < 1) { response.Status.Message.FriendlyMessage = "Supplier Number and Identification is required to process this request"; return(response); } var bidAndTenderObj = _dataContext.cor_bid_and_tender.FirstOrDefault(w => w.SupplierId == request.SupplierId && w.LPOnumber.Trim().ToLower() == request.LPONumber.Trim().ToLower()); if (bidAndTenderObj == null) { bidAndTenderObj = new cor_bid_and_tender(); bidAndTenderObj.ApprovalStatusId = (int)ApprovalStatus.Authorised; bidAndTenderObj.DecisionResult = (int)DecisionResult.Non_Applicable; } var file = _accessor.HttpContext.Request.Form.Files; if (file.Count() > 0) { if (file[0].FileName.Split('.').Length > 2) { response.Status.Message.FriendlyMessage = "Invalid Character detected in file Name"; return(response); } var folderName = Path.Combine("Resources", "Images"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); var fileName = $"{request.LPONumber}-{request.SupplierId}-{DateTime.Now.ToString().Split(" ")[1].Replace(':','-')}"; var type = file[0].ContentType; var fullPath = _env.WebRootPath + "/Resources/" + fileName; var dbPath = _env.WebRootPath + "/Resources/" + fileName; using (FileStream filestrem = System.IO.File.Create(fullPath)) { await file[0].CopyToAsync(filestrem); await filestrem.FlushAsync(); } bidAndTenderObj.ProposalTenderUploadFullPath = fullPath; bidAndTenderObj.ProposalTenderUploadName = "/Resources/" + fileName; bidAndTenderObj.ProposalTenderUploadPath = dbPath; bidAndTenderObj.ProposalTenderUploadType = type; bidAndTenderObj.Extention = file[0].FileName.Split('.')[1]; bidAndTenderObj.SupplierId = request.SupplierId; bidAndTenderObj.LPOnumber = request.LPONumber; } bidAndTenderObj.Paymentterms = _dataContext.cor_paymentterms.Where(w => w.BidAndTenderId == bidAndTenderObj.BidAndTenderId).ToList(); if (bidAndTenderObj.Paymentterms.Count() == 0) { bidAndTenderObj.Paymentterms = new List <cor_paymentterms>(); } await _repo.AddUpdateBidAndTender(bidAndTenderObj); response.Status.IsSuccessful = true; response.Status.Message.FriendlyMessage = "Successful"; return(response); } catch (Exception ex) { #region Log error to file var errorCode = ErrorID.Generate(4); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); response.Status.IsSuccessful = true; response.Status.Message.FriendlyMessage = $"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"; response.Status.Message.TechnicalMessage = ex.ToString(); return(response); #endregion } }
private cor_approvaldetail BuildApprovalDetailObject(BidandTenderStaffApprovalCommand request, cor_bid_and_tender currentItem, int staffId) { var approvalDeatil = new cor_approvaldetail(); var previousDetail = _detailService.GetApprovalDetailsAsync(request.TargetId, currentItem.WorkflowToken).Result; approvalDeatil.ArrivalDate = currentItem.RequestDate; if (previousDetail.Count() > 0) { approvalDeatil.ArrivalDate = previousDetail.OrderByDescending(s => s.ApprovalDetailId).FirstOrDefault().Date; } approvalDeatil.Comment = request.ApprovalComment; approvalDeatil.Date = DateTime.Today; approvalDeatil.StatusId = request.ApprovalStatus; approvalDeatil.TargetId = request.TargetId; approvalDeatil.ReferredStaffId = request.ReferredStaffId; approvalDeatil.StaffId = staffId; approvalDeatil.WorkflowToken = currentItem.WorkflowToken; return(approvalDeatil); }