public ActionResult DeleteConfirmed(int id) { OCMovers_MC4.Models.EstimateForm estimateform = db.EstimateForm.Find(id); db.EstimateForm.Remove(estimateform); db.SaveChanges(); return(RedirectToAction("Index")); }
// // POST: /Administration/Estimates/Create //[HttpPost] //public ActionResult Create(OCMovers_MC4.ViewModel.EstimateForm estimateform, List<Address> addresses ) //{ // if (ModelState.IsValid) // { // db.EstimateForm.Add(estimateform); // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(estimateform); //} // // GET: /Administration/Estimates/Edit/5 //public ActionResult Edit(int id) //{ // OCMovers_MC4.Models.EstimateForm estimateform = db.EstimateForm.Find(id); // return View(estimateform); //} // // POST: /Administration/Estimates/Edit/5 //[HttpPost] //public ActionResult Edit(OCMovers_MC4.ViewModel.EstimateForm estimateform) //{ // if (ModelState.IsValid) // { // db.Entry(estimateform).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(estimateform); //} // // GET: /Administration/Estimates/Delete/5 //public ActionResult Delete(int id) //{ // OCMovers_MC4.Models.EstimateForm estimateform = db.EstimateForm.Find(id); // return View(estimateform); //} public ActionResult CreateCustomerEstimate() { var estId = Convert.ToInt32(RouteData.Values["id"]); OCMovers_MC4.Models.EstimateForm est = db.EstimateForm.FirstOrDefault(x => x.EstimateFormID == estId); var startAddress2 = !string.IsNullOrEmpty(est.loc1Address2) ? ", " + est.loc1Address2 : string.Empty; var endAddress2 = !string.IsNullOrEmpty(est.loc2Address2) ? ", " + est.loc2Address2 : string.Empty; var startApt = !string.IsNullOrEmpty(est.loc1Apartment) ? string.Concat(est.loc1Apartment, ", ") : string.Empty; var endApt = !string.IsNullOrEmpty(est.loc2Apartment) ? string.Concat(est.loc2Apartment, ", ") : string.Empty; var stairsElvStart = !string.IsNullOrEmpty(est.elevStairsCurrent) ? string.Concat(est.elevStairsCurrent) : string.Empty; var stairsElvEnd = !string.IsNullOrEmpty(est.elevStairsDestination) ? string.Concat(est.elevStairsDestination) : string.Empty; var startAddress = string.Concat(est.loc1Address1, startAddress2, ", ", startApt, est.loc1City, ", ", est.loc1State, " ", est.loc1Postal); var endAddress = string.Concat(est.loc2Address1, endAddress2, ", ", endApt, est.loc2City, ", ", est.loc2State, " ", est.loc2Postal); var startFloor = est.dwellingTypeCurrent == "House" ? ", " + est.dwellingTypeCurrentFloorHouse : ", " + est.dwellingTypeCurrentFloorApt.ToString(); var endFloor = est.dwellingTypeCurrent == "House" ? ", " + est.dwellingTypeCurrentFloorHouse : ", " + est.dwellingTypeCurrentFloorApt.ToString(); var startBuilding = !string.IsNullOrEmpty(est.loc1BuildingName) ? string.Concat(est.loc1BuildingName, ": ") : string.Empty; var endBuilding = !string.IsNullOrEmpty(est.loc2BuildingName) ? string.Concat(est.loc2BuildingName, ": ") : string.Empty; var start = string.Concat(startBuilding, startAddress, " (", est.dwellingTypeCurrent, startFloor, ") ", stairsElvStart); var end = string.Concat(endBuilding, endAddress, " (", est.dwellingTypeDestination, endFloor, ") ", stairsElvEnd); var model = new CreateCustomerEstimate() { EstimateFormId = est.EstimateFormID, CustomerName = est.name, PhoneNumber = est.phone, MoveDate = est.moveDateEnd, Start = start, End = end, CreateDate = DateTime.Now }; return(View(model)); }
public JsonResult SendEstimate(OCMovers_MC4.ViewModel.EstimateForm estimateForm, List <Address> addresses, List <EstimateFormInventory> model = null) { Console.WriteLine(addresses); try { if (ModelState.IsValid) { Guid EG = Guid.NewGuid(); estimateForm.EstimateGuid = EG; OCMovers_MC4.Models.EstimateForm newEstimate = new OCMovers_MC4.Models.EstimateForm() { EstimateGuid = EG, Feedback = estimateForm.Feedback, InventoryWriteIn = estimateForm.InventoryWriteIn, InventoryItem = estimateForm.InventoryItem, IsDateFlexible = estimateForm.IsDateFlexible, PreviousCustomer = estimateForm.PreviousCustomer, PreviousCustomerName = estimateForm.PreviousCustomerName, agreeCorrect = estimateForm.agreeCorrect, email = estimateForm.email, estBoxCount = estimateForm.estBoxCount, moveDateEnd = estimateForm.moveDateEnd, moveDescription = estimateForm.moveDescription, name = estimateForm.name, packingServices = estimateForm.packingServices, phone = estimateForm.phone, //old fields not required here dwellingTypeCurrent = estimateForm.dwellingTypeCurrent, dwellingTypeCurrentFloorApt = estimateForm.dwellingTypeCurrentFloorApt, dwellingTypeCurrentFloorHouse = estimateForm.dwellingTypeCurrentFloorHouse, dwellingTypeDestination = estimateForm.dwellingTypeDestination, dwellingTypeDestinationFloorApt = estimateForm.dwellingTypeDestinationFloorApt, dwellingTypeDestinationFloorHouse = estimateForm.dwellingTypeDestinationFloorHouse, loc1BuildingName = estimateForm.loc1BuildingName, loc1Address1 = estimateForm.loc1Address1, loc1Address2 = estimateForm.loc1Address2, loc1Apartment = estimateForm.loc1Apartment, loc1City = estimateForm.loc1City, loc1State = estimateForm.loc1State, loc1Postal = estimateForm.loc1Postal, loc2BuildingName = estimateForm.loc2BuildingName, loc2Address1 = estimateForm.loc2Address1, loc2Address2 = estimateForm.loc2Address2, loc2Apartment = estimateForm.loc2Apartment, loc2City = estimateForm.loc2City, loc2State = estimateForm.loc2State, loc2Postal = estimateForm.loc2Postal, elevStairsCurrent = estimateForm.elevStairsCurrent, elevStairsDestination = estimateForm.elevStairsDestination, elevStairsResExp = estimateForm.elevStairsResExp, stairsToFrontExp = estimateForm.stairsToFrontExp, longWalksToDoorExp = estimateForm.longWalksToDoorExp, specialCareItemExp = estimateForm.specialCareItemExp, //Addresses = new List<Address>(), elevStairsRes = estimateForm.elevStairsRes, longWalksToDoor = estimateForm.longWalksToDoor, numRoomsCurrent = estimateForm.numRoomsCurrent, numRoomsDestination = estimateForm.numRoomsDestination, specialCareItem = estimateForm.specialCareItem, stairsToFront = estimateForm.stairsToFront, submitDate = DateTime.Now, StorageGroundFloorAccessCurrent = estimateForm.StorageGroundFloorAccessCurrent, StorageGroundFloorAccessDestination = estimateForm.StorageGroundFloorAccessDestination, StorageTypeCurrent = estimateForm.StorageTypeCurrent, StorageTypeDestination = estimateForm.StorageTypeDestination, OtherCurrent = estimateForm.OtherCurrent, OtherDestination = estimateForm.OtherDestination }; db.EstimateForm.Add(newEstimate); db.SaveChanges(); //foreach (var a in addresses) //{ // var newAddress = new CustomerAddress() // { // AddressType = a.AddressType, // Address1 = a.Address1, // AptNum = a.AptNum, // BuildingName = a.BuildingName, // City = a.City, // EstimateId = newEstimate.EstimateFormID, // Postcode = a.Postcode, // State = a.State, // AptFloor = a.AptFloor ?? 0, // ElevatorStairs = a.ElevatorStairs, // ElevatorStairsDescription = a.ElevatorStairsDescription, // HouseOrApt = a.HouseOrApt, // HouseStories = a.HouseStories, // Inventory = a.Inventory, // LongWalks = a.LongWalks, // LongWalksDescription = a.LongWalksDescription, // Notes = a.Notes, // NumberOfBedrooms = a.NumberOfBedrooms, // SpecialCare = a.SpecialCare, // SpecialCareDescription = a.SpecialCareDescription, // Stairs = a.Stairs, // StairsDescription = a.StairsDescription, // BoxCount = a.BoxCount // }; // db.CustomerAddress.Add(newAddress); // db.SaveChanges(); //} //newEstimate.Addresses = addresses; UserMailer.Welcome(newEstimate).Send(); return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { result = "success" } }); } else { var es = ModelState.Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); Debug.WriteLine("Model state not valid"); StringBuilder sb = new StringBuilder(); foreach (var c in errors) { sb.Append(string.Concat(c.Key, ": ", c.Errors[0].ErrorMessage, "<br>")); } string output = sb.ToString(); CreateErrorLogEmail(output, null); UserMailer.SendModelStateError(output).Send(); return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { result = output } }); ; } } catch (Exception ex) { var str = new JavaScriptSerializer().Serialize(estimateForm); CreateErrorLogEmail(str, ex); throw; } }