public IHttpActionResult PutCustDocument(int id, CustDocument custDocument) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != custDocument.Id) { return(BadRequest()); } db.Entry(custDocument).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustDocumentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult BuyMotorWeb([FromBody] MotorDetails motorDetails) { if (!ModelState.IsValid) { return(BadRequest("Invalid Motor details")); } var userFound = _context.AspNetUsers.FirstOrDefault(u => u.Email == motorDetails.Email || u.PhoneNumber == motorDetails.PhoneNo); var regTime = DateTime.UtcNow; var timeStamp = new DateTimeOffset(regTime).ToUnixTimeSeconds(); if (userFound == null) { try { //var user = Mapper.Map<UserInputDTO, AspNetUser>(userInput); userFound = new AspNetUser { Firstname = motorDetails.Firstname, Surname = motorDetails.Surname, Email = motorDetails.Email, PhoneNumber = motorDetails.PhoneNo, UserName = motorDetails.Email, IsCoperate = motorDetails.UsageType.ToString() == "2", RegCode = motorDetails.RegNo, CompanyName = motorDetails.companyName != "" ? motorDetails.companyName : null, RegisterationDate = regTime, Address = motorDetails.InsuredAddress, EmailConfirmed = false, PhoneNumberConfirmed = false, TwoFactorEnabled = false, LockoutEnabled = false, AccessFailedCount = 0, IsMobile = false, IsDeleted = false, Id = generateID() + "-" + RandomID() }; _context.AspNetUsers.Add(userFound); _context.SaveChanges(); userFound = _context.AspNetUsers.FirstOrDefault(u => u.Email == motorDetails.Email); // || u.PhoneNumber == motorDetails.PhoneNo } catch (DbEntityValidationException e) { return(Ok(e)); } } //save the vehicle details var vehicledetailsInput = new VehicledetailsInputDTO { ChasisNo = motorDetails.ChasisNo, EngineNo = motorDetails.EngineNo, RegNo = motorDetails.RegNo }; var vehicleDetail = Mapper.Map <VehicledetailsInputDTO, VehicleDetail>(vehicledetailsInput); _context.VehicleDetails.Add(vehicleDetail); _context.SaveChanges(); var vehicleDetailFound = _context.VehicleDetails.FirstOrDefault(vd => vd.RegNo == motorDetails.RegNo && vd.ChasisNo == motorDetails.ChasisNo && vd.EngineNo == motorDetails.EngineNo); // //save the vehicle var vehicle = new Vehicle { UserID = userFound.Id, VehicleMake = motorDetails.VehicleMake, VehicleModel = motorDetails.VehicleModel, VehicleDetailID = vehicleDetailFound.ID, VehicleDate = motorDetails.VehicleDate, VehicleType = vehicleType(motorDetails.UsageType.ToString()), CoverType = userType(motorDetails.UserType.ToString()) + " |" + motorClass(motorDetails.MotorClass.ToString()) + " |" + cardDuration(motorDetails.carduration.ToString()), VehicleValue = motorDetails.VehicleValue.ToString() }; // var vehicle = Mapper.Map<VehicleInputDTO, Vehicle>(vehiclerInput); _context.Vehicles.Add(vehicle); _context.SaveChanges(); var vehicleFound = _context.Vehicles.FirstOrDefault(v => v.VehicleDetailID == vehicleDetailFound.ID); // var intPremium = Convert.ToDouble(motorDetails.premium); byte[] filebaseDocBytes = Convert.FromBase64String(motorDetails.filebase64doc); byte[] filebaseIdBytes = Convert.FromBase64String(motorDetails.filebase64ID); //var transRef = "NSI" + RandomID() + "-" + generateID(); var transRef = "NSI" + generateID(); transRef = transRef.Substring(0, 11); var custDocument = new CustDocument { IdType = "motor", FileType = motorDetails.filetypeID, FileTypeLicence = motorDetails.filetypedoc, IsAchived = false, UserId = userFound.Id, UploadedDate = regTime, IdMeans = filebaseIdBytes, IdLicense = filebaseDocBytes, TransRef = transRef }; _context.CustDocuments.Add(custDocument); _context.SaveChanges(); // Check if there is a promo //if (modelDetails.IsDstv) //{ //} //Insert Quote table // approve should be updated after payment is done var quote = new Quote() { UserId = userFound.Id, VehicleID = vehicleFound.ID, InitialPremium = (decimal)motorDetails.premium, PurchaseDiscount = (decimal)motorDetails.purchaseDiscount, FinalPremium = ((decimal)motorDetails.premium - (decimal)motorDetails.purchaseDiscount), FinalPremiumString = ((decimal)motorDetails.premium - (decimal)motorDetails.purchaseDiscount).ToString(), Approved = false, IsComprehensive = motorClass(motorDetails.MotorClass.ToString()) == "Comprehensive", CanPay = true, Cover = cardDuration(motorDetails.carduration.ToString()), IsMobile = false, TransactionDate = regTime, IsRenewal = false, isDeleted = false, // MyTimestamp = Convert.FromBase64String(timeStamp.ToString()), BizId = 1, HasExcess = false, UsageType = usageType(motorDetails.UsageType.ToString()), Referral = motorDetails.reference, Name = motorDetails.Surname + " " + motorDetails.Firstname, Coverperiod = motorDetails.carduration, InsuredName = motorDetails.Surname + " " + motorDetails.Firstname, InsuredAddress = motorDetails.InsuredAddress, Reference = (motorDetails.reference == null || motorDetails.reference == "") ? "N/A" : motorDetails.reference, IsLive = false, StateId = Convert.ToInt32(motorDetails.state), LgaId = Convert.ToInt32(motorDetails.lga) }; _context.Quotes.Add(quote); _context.SaveChanges(); var quoteFound = _context.Quotes.FirstOrDefault(q => q.UserId == userFound.Id && q.VehicleID == vehicleFound.ID); // Add to payment table var motorPayment = new PaymentDetail() { UserID = userFound.Id, txtRef = transRef, QuoteID = quoteFound.ID, amount = quoteFound.FinalPremium, AmountString = quoteFound.FinalPremium.ToString(), TransactionDate = regTime }; _context.PaymentDetails.Add(motorPayment); _context.SaveChanges(); //update promo table if promo //var promo = _context.Promos.FirstOrDefault(p=>p.Code == motorDetails.promoCode); //if (promo != null) //{ // promo.transactionRef = motorDetails.promoCode; // _context.SaveChanges(); //} var motorPaymentFound = _context.PaymentDetails.FirstOrDefault(p => p.UserID == userFound.Id && p.txtRef == transRef); var intPremium = (int)quoteFound.FinalPremium; var premiumKobo = intPremium * 100; var productID = "6205"; var pay_item_id = "101"; var payment_redirect_url = ConfigurationManager.AppSettings["return_url"]; var MAC_KEY = ConfigurationManager.AppSettings["MAC_KEY"]; // txn_ref + product_id + pay_item_id + amount + site_redirect_url + MacKey // var Hash = (transRef + quoteFound.VehicleID.ToString() + motorPaymentFound.ID.ToString() + intPremium.ToString() + payment_redirect_url + MAC_KEY); var Hash = (transRef + productID + pay_item_id + premiumKobo.ToString() + payment_redirect_url + MAC_KEY); Hash = GenSHA512(Hash); var motorResponse = new MotorResponseDTO { businessClass = "motor", customerName = userFound.Surname + " " + userFound.Firstname, hash = Hash, premium = premiumKobo, premiumString = intPremium.ToString(), quoteID = quoteFound.ID, reference = (motorDetails.reference == null || motorDetails.reference == "") ? "N/A" : motorDetails.reference, transactionRefNo = transRef, vehicledetail = vehicle.VehicleMake + " " + vehicle.VehicleModel + " " + vehicle.VehicleDate, payItemId = pay_item_id // payItemId = motorPaymentFound.ID.ToString() }; //send email //var description = userType(motorDetails.UserType.ToString()) + " |" + // motorClass(motorDetails.MotorClass.ToString()) + " |" + // cardDuration(motorDetails.carduration.ToString()); //SendEmail(userFound, motorDetails, description, intPremium.ToString("C")); return(Ok(motorResponse)); }