예제 #1
0
        public async Task <ActionResult> GetViewingsByDateRange
            (ViewingViewModel dateFilterInputModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var viewingList = await _viewingRepo.GetViewingsByDate(
                        dateFilterInputModel.ViewingDateFilter.StartingDateRange,
                        dateFilterInputModel.ViewingDateFilter.EndingDateRange);

                    if (viewingList == null)
                    {
                        return(HttpNotFound());
                    }

                    model.Viewings = viewingList;
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError
                        (string.Empty, ex.Message);
                }
                return(View("Index", model));
            }
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id.HasValue)
            {
                try
                {
                    var viewingRes = await _viewingRepo.Get(id.Value);

                    if (viewingRes != null)
                    {
                        if (viewingRes.Listing.ImagesContent != null)
                        {
                            var listingImages = new List <ListingImage>
                                                    (viewingRes.Listing.ImagesContent);

                            viewingRes.Listing.ImagesContent = new List <ListingImage>();

                            listingImages.ForEach(i => viewingRes.Listing.ImagesContent.Add(i));
                        }

                        model = _viewingService
                                .GetViewingViewModelFromModel(viewingRes);
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
                return(View(model));
            }
            return(HttpNotFound());
        }
예제 #3
0
        public async Task <ActionResult> Create(ViewingViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.ListingId == 0)
                    {
                        model = await GetDefaultViewModelEntry();

                        model.PickedListingPostalCode = "No Listing is Picked";
                        ModelState.AddModelError(string.Empty, "Please pick a Listing");

                        return(View(model));
                    }

                    var modelState      = ModelState;
                    var viewingToCreate = new Viewing();
                    viewingToCreate = await _viewingService
                                      .GetViewingFromViewModel(model);

                    if (await _viewingService.IsViewingValid
                            (viewingToCreate, ModelState))
                    {
                        var currentLoggedUserId  = User.Identity.GetUserId();
                        var currentLoggedUserRes = await UserIdentityManager
                                                   .GetUserById(currentLoggedUserId);

                        viewingToCreate.CreatedDate = DateTime.Now;
                        viewingToCreate.UpdatedDate = DateTime.Now;

                        viewingToCreate.UserCreatorId =
                            currentLoggedUserRes.registeredUser.ID;

                        viewingToCreate.UserUpdatorId =
                            currentLoggedUserRes.registeredUser.ID;

                        viewingToCreate.IsActive = true;

                        var result = await _viewingRepo.Create
                                         (viewingToCreate);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        model = await GetDefaultViewModelEntry();

                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }

            return(View(model));
        }
예제 #4
0
 public ViewingsController
     (IViewingRepo viewingRepo,
     IViewingService viewingService,
     ViewingViewModel viewingVM,
     SimpleErrorModel errorM)
 {
     _viewingRepo    = viewingRepo;
     _viewingService = viewingService;
     model           = viewingVM;
     errorModel      = errorM;
 }
예제 #5
0
        public async Task <ActionResult> Edit(ViewingViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var modelState = ModelState;

                    var viewingToModify = await _viewingService
                                          .GetViewingFromViewModel(model);

                    viewingToModify.ID            = model.ReadonlyViewingModel.ID;
                    viewingToModify.UserCreatorId = model.ReadonlyViewingModel.UserCreatorId;


                    if (await _viewingService.IsViewingValid
                            (viewingToModify, ModelState))
                    {
                        var currentLoggedUserId = User.Identity.GetUserId();

                        var currentLoggedUserRes = await UserIdentityManager
                                                   .GetUserById(currentLoggedUserId);

                        viewingToModify.UpdatedDate = DateTime.Now;

                        viewingToModify.UserUpdatorId =
                            currentLoggedUserRes.registeredUser.ID;

                        await _viewingRepo.Update(viewingToModify);

                        return(RedirectToAction("Details", new { id = viewingToModify.ID }));
                    }
                    else
                    {
                        var viewingModel = model.ReadonlyViewingModel;
                        model = await GetDefaultViewModelEntry();

                        model.ReadonlyViewingModel = viewingModel;

                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }

            return(View(model));
        }
예제 #6
0
        public async Task <ActionResult> Edit(int?listingId, int?id)
        {
            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));
                }


                var viewingModel = await _viewingRepo.Get(id.Value);

                if (viewingModel == null)
                {
                    return(HttpNotFound());
                }

                //If user Picked a different Listing on Edit
                if (listingId.HasValue)
                {
                    viewingModel.Listing = await _viewingRepo.GetListingById(listingId.Value);
                }

                model = _viewingService.GetViewingViewModelFromModel(viewingModel);

                var tmpModel = await GetDefaultViewModelEntry();

                model.Listings                = tmpModel.Listings;
                model.Customers               = tmpModel.Customers;
                model.Agents                  = tmpModel.Agents;
                model.DurationList            = tmpModel.DurationList;
                model.PickedListingPostalCode =
                    $@"{ viewingModel.Listing.ListingAddress.PostalCode} { viewingModel.Listing.ListingAddress.StreetAddress} { viewingModel.Listing.ListingAddress.Municipality}";
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
            }
            return(View(model));
        }
예제 #7
0
        public async Task <ViewingViewModel> GetDefaultViewModelEntry()
        {
            var viewModel = new ViewingViewModel();
            var listings  = _viewingService.GetListingsList();
            var customers = _viewingService.GetCustomersList();
            var agents    = _viewingService.GetAgentsList();

            await Task.WhenAll(listings, customers, agents);

            viewModel.Listings     = listings.Result;
            viewModel.Customers    = customers.Result;
            viewModel.Agents       = agents.Result;
            viewModel.DurationList = _viewingService.GetDurationSlots();

            return(viewModel);
        }
예제 #8
0
        public ViewingViewModel GetViewingViewModelFromModel(Viewing view)
        {
            var viewmodel = new ViewingViewModel();

            viewmodel.AgentId      = view.ViewingHost.ID;
            viewmodel.ListingId    = view.Listing.ID;
            viewmodel.CustomerID   = view.Customer.ID;
            viewmodel.ViewingStart = view.StartDate.AddMinutes(-TRAVEL_TIME);

            viewmodel.ViewingDuration = (int)(view.EndDate.TimeOfDay.TotalMinutes
                                              - view.StartDate.TimeOfDay.TotalMinutes) - (TRAVEL_TIME);


            viewmodel.ReadonlyViewingModel = view;

            return(viewmodel);
        }
예제 #9
0
        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));
        }
예제 #10
0
        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);
        }