public IHttpActionResult Puttbl_VehicleInfo(int id, tbl_VehicleInfo tbl_VehicleInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tbl_VehicleInfo.Id) { return(BadRequest()); } db.Entry(tbl_VehicleInfo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tbl_VehicleInfoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Posttbl_Payment(tbl_Payment tbl_Payment) { List <string> successDetails = new List <string>(); string[] success = new string[6]; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } tbl_Payment.Payment_Date = DateTime.Now; tbl_Payment.Payment_Status = "Done"; db.tbl_Payment.Add(tbl_Payment); db.SaveChanges(); //int? vehicleid = db.tbl_Policy.ToList().Find(m => m.Id == tbl_Policy.Id).Veh_Id; //tbl_VehicleInfo tbl_VehicleInfo = db.tbl_VehicleInfo.Where(m => m.Id == vehicleid).First(); //int? customerId = db.tbl_VehicleInfo.ToList().Find(m => m.Id == vehicleid).Cust_Id; int?policyid = db.tbl_Payment.ToList().Find(m => m.Id == tbl_Payment.Id).Pol_Id; tbl_Policies tbl_Policiesss = db.tbl_Policies.Find(policyid); if (tbl_Policiesss == null) { return(NotFound()); } tbl_Policies tbl_Policy = db.tbl_Policies.Where(m => m.Id == policyid).First(); int? vehicleId = db.tbl_Policies.ToList().Find(m => m.Id == policyid).Veh_Id; tbl_VehicleInfo tbl_VehicleInfo2 = db.tbl_VehicleInfo.Where(m => m.Id == vehicleId).First(); int? customerId = db.tbl_VehicleInfo.ToList().Find(m => m.Id == vehicleId).Cust_Id; tbl_User tbl_User = db.tbl_User.Where(m => m.Id == customerId).First(); string carModel = tbl_VehicleInfo2.Veh_Model; string carManufacturer = tbl_VehicleInfo2.Manufacturer; string registerationNumber = tbl_VehicleInfo2.Registration_Number; string userName = tbl_User.Firstname; success[0] = carModel; success[1] = carManufacturer; success[2] = registerationNumber; success[3] = userName; success[4] = tbl_Payment.Pol_Id.Value.ToString(); success[5] = tbl_Payment.Id.ToString(); //db.sp_paymentStatuses(tbl_Payment.Pol_Id); db.sp_PaymentStatuss(tbl_Payment.Pol_Id); // db.sp_paymentStatusesforRenew(tbl_Payment.Pol_Id); return(CreatedAtRoute("DefaultApi", new { id = tbl_Payment.Id }, success)); }
public IHttpActionResult Gettbl_VehicleInfo(int id) { tbl_VehicleInfo tbl_VehicleInfo = db.tbl_VehicleInfo.Find(id); if (tbl_VehicleInfo == null) { return(NotFound()); } return(Ok(tbl_VehicleInfo)); }
public IHttpActionResult Deletetbl_VehicleInfo(int id) { tbl_VehicleInfo tbl_VehicleInfo = db.tbl_VehicleInfo.Find(id); if (tbl_VehicleInfo == null) { return(NotFound()); } db.tbl_VehicleInfo.Remove(tbl_VehicleInfo); db.SaveChanges(); return(Ok(tbl_VehicleInfo)); }
public IHttpActionResult Posttbl_Policy(tbl_Policies tbl_Policy) { if (tbl_Policy.Policy_Type != "Third Party") { if (tbl_Policy.Policy_Type != "Comprehensive") { return(BadRequest()); } } if (tbl_Policy.Duration > 3) { return(BadRequest()); } if (tbl_Policy.Duration == 0) { return(BadRequest()); } if (tbl_Policy.Duration < 0) { return(BadRequest()); } tbl_Policy.Policy_Purchase_Date = DateTime.Today; int year = tbl_Policy.Duration; tbl_Policy.Policy_Date = DateTime.Today; tbl_Policy.Policy_Expiry_Date = tbl_Policy.Policy_Purchase_Date.AddYears(year); tbl_Policy.Policy_Approve_Status = "Deactivated"; tbl_Policy.Policy_Payment_Status = "Not Done"; tbl_Policy.Approved_By = "Admin"; int[] paymentDetails = new int[5]; if (tbl_Policy.Policy_Type == "Third Party") { tbl_Policy.Total_IDV = tbl_Policy.Total_IDV / 50; tbl_Policy.Policy_Amount = tbl_Policy.Policy_Amount / 100; } if (tbl_Policy.Total_IDV < 5000) { tbl_Policy.Total_IDV = 6460; } if (tbl_Policy.Policy_Amount < 1000) { tbl_Policy.Policy_Amount = 2900; } tbl_Policy.Policy_Amount = tbl_Policy.Policy_Amount * tbl_Policy.Duration; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tbl_Policies.Add(tbl_Policy); db.SaveChanges(); paymentDetails[0] = tbl_Policy.Id; paymentDetails[1] = tbl_Policy.Policy_Amount; paymentDetails[2] = tbl_Policy.Total_IDV; int?vehicleid = db.tbl_Policies.ToList().Find(m => m.Id == tbl_Policy.Id).Veh_Id; tbl_VehicleInfo tbl_VehicleInfo = db.tbl_VehicleInfo.Where(m => m.Id == vehicleid).First(); int? customerId = db.tbl_VehicleInfo.ToList().Find(m => m.Id == vehicleid).Cust_Id; tbl_User tbl_User = db.tbl_User.Where(m => m.Id == customerId).First(); int UserID = tbl_User.Id; int?VehicleId = tbl_Policy.Veh_Id; //int? vehicleid = db.tbl_Policy.ToList().Find(m => m.Id == tbl_Policy.Id).Veh_Id; // tbl_VehicleInfo tbl_VehicleInfo = db.tbl_VehicleInfo.Find(vehicleid); paymentDetails[3] = VehicleId.Value; paymentDetails[4] = UserID; return(CreatedAtRoute("DefaultApi", new { id = tbl_Policy.Id }, paymentDetails)); }
public IHttpActionResult Posttbl_VehicleInfo(tbl_VehicleInfo tbl_VehicleInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string x = tbl_VehicleInfo.Purchase_Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); DateTime oDate = Convert.ToDateTime(x); tbl_VehicleInfo.Purchase_Date = oDate; int value = DateTime.Compare(tbl_VehicleInfo.Purchase_Date, DateTime.Now); if (value > 0) { tbl_VehicleInfo.Purchase_Date = DateTime.Now.AddDays(-1); } tbl_VehicleInfo.Vehicle_Type = "Four Wheeler"; string model = tbl_VehicleInfo.Veh_Model; tbl_Vehicle_Price tbl_vehicleprice = db.tbl_Vehicle_Price.Find(model); if (tbl_vehicleprice == null) { return(BadRequest()); } int showroomPrice = tbl_vehicleprice.Vehicle_Showroom_Price; DateTime now = DateTime.Now; int year = now.Year; int purchase = tbl_VehicleInfo.Purchase_Date.Year; float difference = year - purchase; int IDV = 0; int policyPrice = 0; int[] bothPrice = new int[4]; if (difference < 1) { IDV = ((showroomPrice) - showroomPrice * 8 / 100); } if (difference >= 1 && difference <= 2) { IDV = ((showroomPrice) - showroomPrice * 11 / 100); } if (difference > 2 && difference <= 3) { IDV = ((showroomPrice) - showroomPrice * 14 / 100); } if (difference > 3 && difference <= 4) { IDV = ((showroomPrice) - showroomPrice * 16 / 100); } if (difference > 4 && difference <= 5) { IDV = ((showroomPrice) - showroomPrice * 18 / 100); } if (difference > 5 && difference <= 6) { IDV = ((showroomPrice) - showroomPrice * 25 / 100); } if (difference > 6) { { IDV = ((showroomPrice) - showroomPrice * 60 / 100); } } policyPrice = IDV / 60; if (policyPrice > 50000) { policyPrice = 45890; } if (policyPrice < 1000) { policyPrice = 3500; } if (IDV < 20000) { IDV = 25000; } bothPrice[0] = IDV; bothPrice[1] = policyPrice; db.tbl_VehicleInfo.Add(tbl_VehicleInfo); db.SaveChanges(); bothPrice[2] = tbl_VehicleInfo.Id; bothPrice[3] = tbl_VehicleInfo.Cust_Id.Value; return(CreatedAtRoute("DefaultApi", new { id = tbl_VehicleInfo.Id }, bothPrice)); }