public async Task <ActionResult> Create(Customer inputModel)
        {
            model.inputModel = inputModel;

            if (ModelState.IsValid)
            {
                try
                {
                    var currentLoggedUserId  = User.Identity.GetUserId();
                    var currentLoggedUserRes = await UserIdentityManager
                                               .GetUserById(currentLoggedUserId);

                    inputModel.UserCreatorId = currentLoggedUserRes.registeredUser.ID;
                    inputModel.UserUpdatorId = currentLoggedUserRes.registeredUser.ID;
                    inputModel.DateCreated   = DateTime.Now;
                    inputModel.DateUpdated   = DateTime.Now;
                    inputModel.IsActive      = true;

                    await _customerRepo.Create(inputModel);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(View("Create", model));
                }
            }
            return(View("Create", model));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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));
        }
        public async Task <ActionResult> UserProfile()
        {
            try
            {
                var currentLoggedUserId = User.Identity.GetUserId();

                var currentLoggedUserRes = await UserIdentityManager.GetUserById
                                               (currentLoggedUserId);


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


                var user = await _userRepo.Get
                               (currentLoggedUserRes.registeredUser.ID);

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

                var model = GetDefaultProfileViewModel(user);


                if (user.RoleID == RoleNames.AGENT)
                {
                    model.IsTypeAgent = true;
                }
                else
                {
                    model.IsTypeAgent = false;
                }


                return(View(model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(new UserProfileViewModel()));
            }
        }
        public async Task <ActionResult> Edit(CustomerViewModel returnModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var currentLoggedUserId = User.Identity.GetUserId();

                    var currentLoggedUserRes = await UserIdentityManager
                                               .GetUserById(currentLoggedUserId);

                    if (currentLoggedUserRes != null)
                    {
                        returnModel.inputModel.UserUpdatorId =
                            currentLoggedUserRes.registeredUser.ID;

                        returnModel.inputModel.DateUpdated = DateTime.Now;

                        await _customerRepo.Update(returnModel.inputModel);

                        model.inputModel = returnModel.inputModel;


                        return(View("Details", model));
                    }
                    else
                    {
                        return(HttpNotFound());
                    }
                }
                catch (Exception ex)
                {
                    model.inputModel = returnModel.inputModel;

                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(View("Edit", model));
                }
            }
            model.inputModel = returnModel.inputModel;

            return(View("Edit", model));
        }
Ejemplo n.º 7
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));
        }
        public async Task <ActionResult> VerifyUser(int?userId)
        {
            try
            {
                if (userId.HasValue)
                {
                    var userFound = await _userRepo.Get(userId.Value);

                    var currentLoggedUserId = User.Identity.GetUserId();

                    var currentLoggedUserRes = await UserIdentityManager.GetUserById
                                                   (currentLoggedUserId);

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

                    userFound.IsVerified = true;

                    userFound.CurrentDrivingLicense.UserUpdatorId =
                        currentLoggedUserRes.registeredUser.ID;


                    var res = await _userRepo.Update(userFound);

                    return(RedirectToAction("UserVerificationList",
                                            new { selectedUser = userFound.ID }));
                }

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

                return(View("UserVerificationList",
                            new VerificationListViewModel()));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Edit(ListingViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var listingFromDb = await _listingRepo.Get(model.InputModel.ID);

                    model.InputModel.ImagesContent = listingFromDb.ImagesContent;

                    var modelToUpdate = model.InputModel;

                    if (!_imageHelper.IsPostedFilesListEmpty(model.ListingImageFiles))
                    {
                        if (_imageHelper.HasImageListExceededSizeLimit
                                (model.ListingImageFiles))
                        {
                            ModelState.AddModelError
                                (string.Empty,
                                "File upload limit exceeded (more than 7 files)");

                            model = await GetDefaultViewModelEntry();

                            model.InputModel = modelToUpdate;

                            model.ExistingListingImages =
                                ListingViewHelperUtilites.SetImagesToListItems
                                    (modelToUpdate.ImagesContent.ToList());

                            return(View(model));
                        }

                        if (_imageHelper.isValidFileUpload(model.ListingImageFiles))
                        {
                            var imagesList = model.ListingImageFiles;
                            _imageHelper.SetModelImages
                                (modelToUpdate, imagesList);
                        }
                        else
                        {
                            ModelState.AddModelError
                                (string.Empty,
                                "One or more File uploads was not valid");

                            model = await GetDefaultViewModelEntry();

                            model.InputModel = modelToUpdate;

                            return(View(model));
                        }
                    }

                    _imageHelper.ArchiveCheckedImages
                        (model.ExistingListingImages, modelToUpdate.ImagesContent.ToList());


                    if (modelToUpdate.ImagesContent
                        .Count(i => !i.IsArchived) > 7)
                    {
                        ModelState.AddModelError
                            (string.Empty,
                            "A listing can't have more than 7 Images");

                        model = await GetDefaultViewModelEntry();

                        model.InputModel = modelToUpdate;

                        var imagesContentList =
                            modelToUpdate.ImagesContent.
                            Where(i => i.ID > 0).ToList();


                        model.ExistingListingImages =
                            ListingViewHelperUtilites.SetImagesToListItems
                                (imagesContentList);

                        return(View(model));
                    }


                    var currentLoggedUserId = User.Identity.GetUserId();

                    var currentLoggedUserRes = await UserIdentityManager
                                               .GetUserById(currentLoggedUserId);

                    var tmpModel = ListingViewHelperUtilites
                                   .MapHeatingAndFeaturesToListingModel(model);


                    modelToUpdate.Heating       = tmpModel.Heating;
                    modelToUpdate.Features      = tmpModel.Features;
                    modelToUpdate.DateUpdated   = DateTime.Now;
                    modelToUpdate.UserUpdatorId = currentLoggedUserRes.registeredUser.ID;


                    await _listingRepo.Update(modelToUpdate);

                    model.InputModel = await _listingRepo.Get(modelToUpdate.ID);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);

                var inputModel = model.InputModel;
                model = await GetDefaultViewModelEntry();

                model.InputModel = inputModel;


                model.FeaturesListToSelect.
                SetFeaturesTypesToListItems(model.InputModel.Features);

                model.HeatingListToSelect.
                SetHeatingTypesToListItems(model.InputModel.Heating);

                return(View(model));
            }

            return(View("Details", model));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Create(ListingViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var modelToInsert = model.InputModel;

                    var currentLoggedUserId  = User.Identity.GetUserId();
                    var currentLoggedUserRes = await UserIdentityManager.GetUserById(currentLoggedUserId);

                    modelToInsert = ListingViewHelperUtilites
                                    .MapHeatingAndFeaturesToListingModel(model);


                    modelToInsert.DateCreated   = DateTime.Now;
                    modelToInsert.DateUpdated   = DateTime.Now;
                    modelToInsert.UserCreatorId = currentLoggedUserRes.registeredUser.ID;
                    modelToInsert.UserUpdatorId = currentLoggedUserRes.registeredUser.ID;
                    modelToInsert.IsActive      = true;


                    if (!_imageHelper.IsPostedFilesListEmpty(model.ListingImageFiles))
                    {
                        if (_imageHelper.HasImageListExceededSizeLimit(model.ListingImageFiles))
                        {
                            ModelState.AddModelError
                                (string.Empty,
                                "File upload limit exceeded (more than 7 files)");

                            model = await GetDefaultViewModelEntry();

                            model.InputModel = modelToInsert;

                            return(View(model));
                        }

                        if (_imageHelper.isValidFileUpload(model.ListingImageFiles))
                        {
                            var imagesList = model.ListingImageFiles;
                            _imageHelper.SetModelImages
                                (modelToInsert, imagesList);
                        }
                        else
                        {
                            ModelState.AddModelError
                                (string.Empty,
                                "One or more File uploads was not valid");

                            model = await GetDefaultViewModelEntry();

                            model.InputModel = modelToInsert;

                            return(View(model));
                        }
                    }

                    int res = await _listingRepo.Create(modelToInsert);

                    return(RedirectToAction("Details", new { id = modelToInsert.ID }));
                }
                else
                {
                    var tmpModel = model.InputModel;
                    model = await GetDefaultViewModelEntry();

                    model.InputModel = tmpModel;

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

                return(View(model));
            }
        }
        public async Task <ActionResult> Edit(OperatingUser inputModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var currentLoggedUserId = User.Identity.GetUserId();

                    var currentLoggedUserRes = await UserIdentityManager.GetUserById
                                                   (currentLoggedUserId);


                    var userMappedRes = inputModel;
                    userMappedRes.UserUpdatorId = currentLoggedUserRes.registeredUser.ID;
                    userMappedRes.UpdatedDate   = DateTime.Now;

                    var identityUser = await UserIdentityManager
                                       .GetUserFromModelId(userMappedRes.ID);

                    if (identityUser != null)
                    {
                        var result = await UserIdentityManager.Changerole
                                         (identityUser, userMappedRes.RoleID);

                        userMappedRes.IsActive = true;

                        if (userMappedRes.RoleID != RoleNames.AGENT)
                        {
                            userMappedRes.IsVerified = true;
                        }



                        var res = await _userRepo.Update(userMappedRes);

                        if (res > 0)
                        {
                            return(RedirectToAction("Details",
                                                    new { id = userMappedRes.ID }));
                        }
                        else
                        {
                            model.InputModel = inputModel;
                            model.rolesList  = await UserIdentityManager.GetRoles();

                            return(View("Edit", model));
                        }
                    }
                }
                catch (Exception ex)
                {
                    model.InputModel = inputModel;
                    model.rolesList  = await UserIdentityManager.GetRoles();

                    ModelState.AddModelError(string.Empty, ex.Message);

                    return(View("Edit", model));
                }
            }
            model.InputModel = inputModel;
            model.rolesList  = await UserIdentityManager.GetRoles();

            return(View("Edit", model));
        }