public async Task <ActionResult> Create(int?listingId) { try { var currentLoggedUserId = User.Identity.GetUserId(); var currentLoggedUserRes = await UserIdentityManager.GetUserById (currentLoggedUserId); if (!currentLoggedUserRes.registeredUser.IsVerified && currentLoggedUserRes.registeredUser.RoleID == RoleNames.AGENT) { errorModel.ErrorMessage = "Agent cannot access viewing resource.\n Agent is not verified"; return(View(NOT_AUTHORIZED_PATH, errorModel)); } model = await GetDefaultViewModelEntry(); if (listingId.HasValue) { model.ListingId = listingId.Value; var listingInDb = await _viewingRepo.GetListingById(model.ListingId); model.PickedListingPostalCode = $@"{listingInDb.ListingAddress.PostalCode} { listingInDb.ListingAddress.StreetAddress} {listingInDb.ListingAddress.Municipality}"; } else { model.PickedListingPostalCode = "No Listing is Picked"; } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return(View(model)); }
public async Task <Viewing> GetViewingFromViewModel(ViewingViewModel viewModel) { var agent = _repo.GetAgentById(viewModel.AgentId); var customer = _repo.GetCustomerById(viewModel.CustomerID); var listing = _repo.GetListingById(viewModel.ListingId); await Task.WhenAll(agent, customer, listing); Viewing res = new Viewing(); res.ViewingHost = agent.Result; res.Customer = customer.Result; res.Listing = listing.Result; res.StartDate = viewModel.ViewingStart.AddMinutes(TRAVEL_TIME); res.EndDate = res.StartDate.AddMinutes(viewModel.ViewingDuration). AddMinutes(TRAVEL_TIME); //If null means there is a new entry res.IsActive = viewModel.ReadonlyViewingModel == null ? true : viewModel.ReadonlyViewingModel.IsActive; return(res); }