public DeliveryInfoBindingModel PrepareDeliveryInfoModelForAdding()
        {
            var model = new DeliveryInfoBindingModel();

            this.PopulateSelectLists(model);

            return(model);
        }
        public async Task AddDeliveryInfoToUserAsync(ClaimsPrincipal user, DeliveryInfoBindingModel model)
        {
            var dbUser = await this.userManager.GetUserAsync(user);

            var deliveryInfoDbModel = this.mapper.Map <DeliveryInfo>(model);

            dbUser.DeliveryInfos.Add(deliveryInfoDbModel);

            this.DbContext.SaveChanges();
        }
        public async Task <IActionResult> Add(DeliveryInfoBindingModel model)
        {
            if (ModelState.IsValid == false)
            {
                this.AddStatusMessage(this.ModelState);
                return(this.RedirectToAction("Add"));
            }

            await this.userDeliveryInfoService.AddDeliveryInfoToUserAsync(this.User, model);

            return(RedirectToAction("Index", "Account"));
        }
        public async Task <bool> EditDeliveryInfoAsync(ClaimsPrincipal user, DeliveryInfoBindingModel model, string deliveryInfoId)
        {
            var deliveryInfoModel = GetDeliveryInfoFromUser(user, deliveryInfoId);

            if (deliveryInfoModel == null)
            {
                return(false);
            }

            this.mapper.Map(model, deliveryInfoModel);

            await this.DbContext.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Edit(DeliveryInfoBindingModel model, string id)
        {
            if (this.ModelState.IsValid == false)
            {
                this.AddStatusMessage(this.ModelState);
                return(this.RedirectToAction("Edit"));
            }

            var isSuccess = await this.userDeliveryInfoService.EditDeliveryInfoAsync(this.User, model, id);

            if (isSuccess == false)
            {
                this.AddStatusMessage(ControllerConstats.ErrorMessageWrongId, ControllerConstats.MessageTypeDanger);
                return(this.RedirectToAction("Edit"));
            }

            return(this.Redirect("/Identity/Account/Index"));
        }
        private void PopulateSelectLists(
            DeliveryInfoBindingModel model,
            District selectedDistrict             = null,
            PopulatedPlace selectedPopulatedPlace = null)
        {
            model.AllDistricts = GetDistrictsAsSelectList();

            model.AllPopulatedPlaces = GetPopulatedPlacesAsSelectList();

            AddDefaultPopulatedPlace(model.AllPopulatedPlaces);

            if (selectedDistrict == null || selectedPopulatedPlace == null)
            {
                AddDefaultDistrict(model.AllDistricts);
            }
            else
            {
                model.AllDistricts
                .First(d => d.Value == selectedDistrict.Id).Selected = true;

                model.AllPopulatedPlaces
                .First(pp => pp.Value == selectedPopulatedPlace.Id).Selected = true;
            }
        }