public async Task UpdatePlace(EditPlaceViewModel placeModel) { var place = await _context.Places.Where(p => p.Id == placeModel.Id && p.ClientUserId == _userProvider.GetUserId()).FirstOrDefaultAsync(); if (place == null) { return; } place.UpdateProperties(placeModel); await _context.SaveChangesAsync(); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var enumVals = Enum.GetValues(typeof(BusinessType)).Cast <BusinessType>(); businessType.ItemsSource = enumVals.ToList(); var promotionEnumVals = Enum.GetValues(typeof(PromotionType)).Cast <PromotionType>(); promotionType.ItemsSource = promotionEnumVals.ToList(); await EditPlaceViewModel.LoadDataAsync(); }
private async void SubmitOnClick(object sender, RoutedEventArgs e) { try { if (ValidateInput("business")) { await EditPlaceViewModel.SaveTaskAsync(); Notification.Show(5000); } } catch (Exception ex) { Console.WriteLine(ex); } }
private async void EditEvent(object sender, RoutedEventArgs e) { try { if (ValidateInput("event")) { await EditPlaceViewModel.EditEvent(EventViewModel); Notification.Show(5000); } } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task <IActionResult> Edit(int id) { var user = await this.userManager.GetUserAsync(this.User); var place = this.placesService.GetById <EditPlaceViewModel>(id); if (place == null || place.User.Id != user.Id) { return(this.NotFound()); } var categories = this.categoriesService.GetAll <CategoryDropDownViewModel>(); var cities = this.citiesService.GetAll <CityDropDownViewModel>(); var extras = this.extrasService.GetAll <ExtraViewModel>(); foreach (var extra in extras) { var placeExtra = place.PlaceExtras.FirstOrDefault(x => x.Extra.Name == extra.Name); if (placeExtra != null) { extra.IsSelected = true; } } var viewModel = new EditPlaceViewModel { Id = place.Id, Name = place.Name, CategoryId = place.CategoryId, CityId = place.CityId, Address = place.Address, Description = place.Description, PriceByNight = place.PriceByNight, BedroomsNum = place.BedroomsNum, BathroomsNum = place.BathroomsNum, MaxGuest = place.MaxGuest, BedsNum = place.BedsNum, User = place.User, Pets = place.Pets, Smoking = place.Smoking, Categories = categories, Cities = cities, Extras = extras.ToList(), }; return(this.View(viewModel)); }
public async Task <IActionResult> Edit(int?id, EditPlaceViewModel placeModel) { if (!id.HasValue || id.Value != placeModel.Id) { return(NotFound()); } if (ModelState.IsValid) { await _placesService.UpdatePlace(placeModel); return(RedirectToAction("Details", new { id = placeModel.Id })); } ModelState.AddModelError(string.Empty, "Please fill in required fields."); return(View(placeModel)); }
private async void RemoveSelectedEvent(object sender, RoutedEventArgs e) { var removeEvent = (EventViewModel)EventsGridView.SelectedItem; if (removeEvent != null) { EventNotPickedValidationMessage.Visibility = Visibility.Collapsed; EditPlaceViewModel.BusinessViewModel.Events.Remove(removeEvent); await EditPlaceViewModel.RemoveEventFromBusiness(removeEvent); Notification.Show(5000); } else { EventNotPickedValidationMessage.Visibility = Visibility.Visible; } }
private async void OnAddPromotionButton(object sender, RoutedEventArgs e) { try { if (ValidateInput("promotion")) { PromotionViewModel.Creation = DateTime.UtcNow; EditPlaceViewModel.BusinessViewModel.Promotions.Add(PromotionViewModel); await EditPlaceViewModel.AddPromotionToBusiness(); Notification.Show(5000); } } catch (Exception ex) { Console.WriteLine(ex); } }
private async void RemoveSelectedPromotion(object sender, RoutedEventArgs e) { var removePromotion = (PromotionViewModel)PromotionsGridView.SelectedItem; if (removePromotion != null) { PromotionNotPickedValidationMessage.Visibility = Visibility.Collapsed; EditPlaceViewModel.BusinessViewModel.Promotions.Remove(removePromotion); await EditPlaceViewModel.RemovePromotionFromBusiness(removePromotion); Notification.Show(5000); } else { PromotionNotPickedValidationMessage.Visibility = Visibility.Visible; } }
public ActionResult EditPlace(EditPlaceViewModel epvm1) { if (ModelState.IsValid) { if ((string)Session["userCode"] == "admin") { try { if (epvm1.PlaceId != 0) { Place place = (from c in entity.Places where c.PlaceId == epvm1.PlaceId select c).FirstOrDefault(); if (epvm1.PlaceTypeId == null) { epvm1.PlaceTypeId = Convert.ToInt32(place.PlaceTypeId); } if (epvm1.PlaceDetail == null) { epvm1.PlaceDetail = place.PlaceDetail; } Place p = (from c in entity.Places where c.PlaceId == epvm1.PlaceId select c).SingleOrDefault(); p.PlaceDetail = epvm1.PlaceDetail; p.PlaceTypeId = epvm1.PlaceTypeId; p.PlaceAddress = epvm1.PlaceAddress; p.PlaceName = epvm1.PlaceName; if (entity.SaveChanges() > 0) { ModelState.Clear(); TempData["EditPlace"] = "done"; return(RedirectToAction("SearchPlaceDetail", "Place", new { PlaceId = epvm1.PlaceId })); } else { TempData["EditPlace"] = "Problem occured"; return(RedirectToAction("SearchPlaceDetail", "Place", new { PlaceId = epvm1.PlaceId })); } } else { TempData["EditPlace"] = "Not chosen any data"; return(RedirectToAction("SearchPlaceDetail", "Place", new { PlaceId = epvm1.PlaceId })); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Admin", "EditPlace"))); } } else { Session["message"] = "please log in First"; return(RedirectToAction("Welcome", "Home")); } } else { PlaceDetailViewModel sp = new PlaceDetailViewModel(); var p = (from c in entity.Places join e in entity.PlacePictures on c.PlaceProfilePicId equals e.PlacePictureId into ppl from e in ppl.DefaultIfEmpty() join f in entity.Countries on c.CountryId equals f.CountryId join g in entity.Cities on c.CityId equals g.CityId join k in entity.PlaceTypes on c.PlaceTypeId equals k.PlaceTypeId where c.PlaceId == epvm1.PlaceId orderby c.PlaceFavourite descending select new { c.PlaceId, c.PlaceName, e.PlacePictureData, k.PlaceTypeId, c.PlaceAddress, c.PlaceFavourite, f.CountryName, g.CityName, c.PlaceDetail, g.CityId, f.CountryId, k.PlaceTypeName, c.PlaceAdminsPermit, }).First(); if (p != null) { sp.PlacePictureData = p.PlacePictureData; sp.PlaceId = p.PlaceId; sp.PlaceName = p.PlaceName; sp.PlaceAddress = p.PlaceAddress; sp.PlaceLike = Convert.ToInt32(p.PlaceFavourite); sp.PlaceTypeName = p.PlaceTypeName; sp.CityName = p.CityName; sp.CountryName = p.CountryName; string st = CutDetail.StripHTML(p.PlaceDetail); sp.PlaceShortDetail = CutDetail.Truncate(st, 40); sp.PlaceFullDetail = p.PlaceDetail; sp.PlaceCityId = p.CityId; sp.PlaceCountryId = p.CountryId; sp.PlaceTypeId = p.PlaceTypeId; sp.PlaceAdminPermit = Convert.ToBoolean(p.PlaceAdminsPermit); } var q = sp; ViewData["pl"] = q; EditPlaceViewModel epvm = new EditPlaceViewModel(); epvm.CountryId = q.CountryId; epvm.CityId = q.CityId; epvm.PlaceName = q.PlaceName; epvm.PlaceAddress = q.PlaceAddress; epvm.PlaceTypeList = new SelectList(entity.PlaceTypes, "PlaceTypeId", "PlaceTypeName"); return(View(epvm)); } }
public ActionResult EditPlace(int PlaceId) { if ((string)Session["userCode"] == "admin") { try { PlaceDetailViewModel sp = new PlaceDetailViewModel(); var p = (from c in entity.Places join e in entity.PlacePictures on c.PlaceProfilePicId equals e.PlacePictureId into ppl from e in ppl.DefaultIfEmpty() join f in entity.Countries on c.CountryId equals f.CountryId join g in entity.Cities on c.CityId equals g.CityId join k in entity.PlaceTypes on c.PlaceTypeId equals k.PlaceTypeId where c.PlaceId == PlaceId orderby c.PlaceFavourite descending select new { c.PlaceId, c.PlaceName, e.PlacePictureData, k.PlaceTypeId, c.PlaceAddress, c.PlaceFavourite, f.CountryName, g.CityName, c.PlaceDetail, g.CityId, f.CountryId, k.PlaceTypeName, c.PlaceAdminsPermit, }).First(); if (p != null) { sp.PlacePictureData = p.PlacePictureData; sp.PlaceId = p.PlaceId; sp.PlaceName = p.PlaceName; sp.PlaceAddress = p.PlaceAddress; sp.PlaceLike = Convert.ToInt32(p.PlaceFavourite); sp.PlaceTypeName = p.PlaceTypeName; sp.CityName = p.CityName; sp.CountryName = p.CountryName; string st = CutDetail.StripHTML(p.PlaceDetail); sp.PlaceShortDetail = CutDetail.Truncate(st, 40); sp.PlaceFullDetail = p.PlaceDetail; sp.PlaceCityId = p.CityId; sp.PlaceCountryId = p.CountryId; sp.PlaceTypeId = p.PlaceTypeId; sp.PlaceAdminPermit = Convert.ToBoolean(p.PlaceAdminsPermit); } var q = sp; ViewData["pl"] = q; EditPlaceViewModel epvm = new EditPlaceViewModel(); epvm.CountryId = q.CountryId; epvm.CityId = q.CityId; epvm.PlaceName = q.PlaceName; epvm.PlaceAddress = q.PlaceAddress; epvm.PlaceTypeList = new SelectList(entity.PlaceTypes, "PlaceTypeId", "PlaceTypeName"); return(View(epvm)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Place", "EditPlace"))); } } else { Session["message"] = "please log In first."; return(RedirectToAction("Welcome", "Home")); } }