public ActionResult ModalEdit(int Id) { if (!AuthorizationProvider.IsAccountEditor() && !AuthorizationProvider.IsViewer()) { return(RedirectToAction("Index", "AirbnbAccount") .WithError("It looks like you do not have permisssion to edit this Airbnb account.")); } try { ViewBag.Title = "Edit Airbnb Account"; ViewBag.ButtonText = "Update Airbnb Account"; AirbnbAccountProvider dataProvider = new AirbnbAccountProvider(_dbContext); AirbnbAccount account = dataProvider.Retrieve(Id); if (account == null) { return(RedirectToAction("NotFound", "Error")); } PropertyProvider propertyProvider = new PropertyProvider(_dbContext); var relatedProperties = propertyProvider.GetAirbnbAccountRelatedProperties(account.Email); account.ActiveListings = relatedProperties.ActiveListings; account.In_activeListings = relatedProperties.InactiveListings; account.ofListingsinLAMarket = relatedProperties.ListingsInLAMarket; account.ofListingsinNYCMarket = relatedProperties.ActiveListings; account.Pending_Onboarding = relatedProperties.PendingOnboarding; if (account.Vertical == null) { account.Vertical = string.Empty; } if (account.Status == null) { account.Status = string.Empty; } return(PartialView("_AirbnbAccountEditFormPartial", account)); } catch (Exception ex) { // TODO: log } return(RedirectToAction("Index", "AirbnbAccount") .WithError("The Airbnb Account item cannot be found.")); }
public JsonResult ModalEdit(AirbnbAccount form) { if (!AuthorizationProvider.IsAccountEditor()) { return(Json("denied", JsonRequestBehavior.AllowGet)); } try { if (ModelState.IsValid) { AirbnbAccountProvider dataProvider = new AirbnbAccountProvider(_dbContext); // make the date to PST time zone to store in DB using UTC if (form.DateAdded != null) { form.DateAdded = form.DateAdded.Value.Date.AddHours(11); } if (form.DOB1 != null) { form.DOB1 = form.DOB1.Value.Date.AddHours(11); } if (form.DOB2 != null) { form.DOB2 = form.DOB2.Value.Date.AddHours(11); } if (form.Id == 0) // new airbnb account { //form.DateAdded = DateTime.Now.Date; PropertyProvider propertyProvider = new PropertyProvider(_dbContext); var relatedProperties = propertyProvider.GetAirbnbAccountRelatedProperties(form.Email); form.ActiveListings = relatedProperties.ActiveListings; form.In_activeListings = relatedProperties.InactiveListings; form.ofListingsinLAMarket = relatedProperties.ListingsInLAMarket; form.ofListingsinNYCMarket = relatedProperties.ActiveListings; form.Pending_Onboarding = relatedProperties.PendingOnboarding; dataProvider.Create(form); } else // updating airbnb account { var account = dataProvider.Retrieve(form.Id); if (account != null) { // need to set CreatedBy and CreatedDate a they are not part of form form.CreatedDate = account.CreatedDate; form.CreatedBy = account.CreatedBy; dataProvider.Update(form.Id, form); } } dataProvider.Commit(); return(Json(form.Id.ToString(), JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { // TODO: log this.ModelState.AddModelError("", ex); } return(Json(string.Empty, JsonRequestBehavior.AllowGet)); }