public IHttpActionResult PostAssetQuotation() { long assetRequestId, vendorId, quantity = 0; decimal price, cgst, sgst; string comments = string.Empty; string status = string.Empty; string createdBy = string.Empty; try { HttpResponseMessage response = new HttpResponseMessage(); var httpRequest = HttpContext.Current.Request; assetRequestId = Convert.ToInt64(httpRequest.Form["EntityTypeId"]); vendorId = Convert.ToInt64(httpRequest.Form["VendorId"]); quantity = Convert.ToInt64(httpRequest.Form["Quantity"]); price = Convert.ToDecimal(httpRequest.Form["Price"]); comments = httpRequest.Form["Comments"]; cgst = Convert.ToDecimal(httpRequest.Form["CGST"]); sgst = Convert.ToDecimal(httpRequest.Form["SGST"]); createdBy = httpRequest.Form["CreatedBy"]; var assetVendor = db.AssetQuotations.Where(x => x.AssetVendorId == vendorId && x.AssetRequestId == assetRequestId && x.IsActive == true).Select(x => x.Id).FirstOrDefault(); if (assetVendor == 0) { if (httpRequest.Form.Keys.Count > 0) { AssetQuotation assetQuotation = new AssetQuotation(); assetQuotation.AssetRequestId = assetRequestId; assetQuotation.AssetVendorId = vendorId; assetQuotation.Price = price; assetQuotation.Quantity = quantity; assetQuotation.Comments = (comments == "undefined") ? string.Empty : comments; assetQuotation.Documents = ""; assetQuotation.CGST = cgst; assetQuotation.SGST = sgst; assetQuotation.IsActive = true; assetQuotation.CreatedOn = System.DateTime.Now; assetQuotation.CreatedBy = (createdBy == "undefined") ? 0 : Convert.ToInt16(createdBy); db.AssetQuotations.Add(assetQuotation); db.SaveChanges(); var fileUpload = new AssetDocumentsController(); var result = fileUpload.FileUpload(assetQuotation.Id, Convert.ToInt16(createdBy)); status = "success"; } } else { status = "exist"; } } catch (Exception) { throw; } return(Ok(status)); }
// POST api/RaiseRequest public IHttpActionResult PostAssetQuoteApproval() { long assetQuotationId, entityTypeId; int loginId; string comments, status = string.Empty, PONumber = string.Empty, sdate = string.Empty; bool isAwaitingNextApproval; long dbMaxPONumber = 0; try { HttpResponseMessage response = new HttpResponseMessage(); var httpRequest = HttpContext.Current.Request; assetQuotationId = Convert.ToInt64(httpRequest.Form["AssetQuotationId"]); comments = httpRequest.Form["Comments"]; isAwaitingNextApproval = Convert.ToBoolean(httpRequest.Form["IsAwaitingNextApproval"]); loginId = Convert.ToInt32(httpRequest.Form["LoginId"]); entityTypeId = Convert.ToInt64(httpRequest.Form["EntityTypeId"]); string AssetStatus = string.Empty; bool IsAwaitingNxtApproval = false; if (isAwaitingNextApproval == true) { IsAwaitingNxtApproval = true; AssetStatus = "Awaiting Quotation Approval"; } else { AssetStatus = "Awaiting PO"; } var dbAssetStatusId = db.AssetStatus.Where(c => c.Name.ToUpper() == AssetStatus.ToUpper()).Select(x => x.Id).FirstOrDefault(); var dbAssetRequestId = db.AssetQuotations.Where(c => c.Id == assetQuotationId).Select(x => x.AssetRequestId).FirstOrDefault(); AssetQuoteApproval assetQuoteApproval = new AssetQuoteApproval(); assetQuoteApproval.AssetQuotationId = assetQuotationId; assetQuoteApproval.ApprovedBy = loginId; //Need to modify assetQuoteApproval.ApprovedOn = System.DateTime.Now; assetQuoteApproval.IsAwaitingNextApproval = IsAwaitingNxtApproval; assetQuoteApproval.Comments = comments; assetQuoteApproval.CreatedBy = loginId; assetQuoteApproval.CreatedOn = System.DateTime.Now; db.AssetQuoteApprovals.Add(assetQuoteApproval); if (httpRequest.Form.Keys.Count > 0) { var fileUpload = new AssetDocumentsController(); var result = fileUpload.FileUpload(entityTypeId, loginId); } db.SaveChanges(); var assetRequest = db.AssetRequests.SingleOrDefault(x => x.Id == dbAssetRequestId); // Add the PO Number exists in AssetRequest table sdate = DateTime.Now.ToShortDateString().Replace(@"-", ""); dbMaxPONumber = db.AssetRequests.Where(a => a.PONumber != null).Count(); dbMaxPONumber = dbMaxPONumber + 1; PONumber = "PO_" + dbMaxPONumber + "_" + sdate; if (assetRequest != null) { assetRequest.AssetQuotationId = assetQuotationId; assetRequest.PONumber = PONumber; assetRequest.AssetStatusId = dbAssetStatusId; assetRequest.LastModifiedOn = System.DateTime.Now; db.SaveChanges(); } status = "success"; AssetHistory assetHistory = new AssetHistory(); assetHistory.AssetRequestId = Convert.ToInt32(dbAssetRequestId); assetHistory.TargetStatusId = dbAssetStatusId; assetHistory.StatusChangedBy = loginId; assetHistory.StatusModifiedOn = System.DateTime.Now; assetHistory.Comments = comments; db.AssetHistories.Add(assetHistory); db.SaveChanges(); } catch (Exception) { throw; } return(Ok(status)); }