Exemplo n.º 1
0
        public IActionResult EditAddress(AddressViewModel model)
        {
            if (ModelState.IsValid)
            {
                //get account id from cookies
                int accountid = Convert.ToInt32(User.Claims.Where(c => c.Type == "Id").Select(c => c.Value).SingleOrDefault());

                Address checkAddress = this._account.GetAddressById(model.Id, accountid);
                //Check if userinput has changes
                bool changed = checkAddress.Country != model.Country || checkAddress.City != model.City || checkAddress.StreetName != model.StreetName || checkAddress.StreetNumber != model.StreetNumber || checkAddress.ZipCode != model.ZipCode;

                if (changed)
                {
                    //copies viewmodel to model
                    Address address = model.CopyTo();
                    if (this._account.UpdateAddress(address))
                    {
                        TempData["message"] = "Address has been updated!";
                        return(RedirectToAction("Profile", "Account", new { id = model.Id }));
                    }
                    TempData["errormessage"] = "Address cannot be updated!";
                    return(RedirectToAction("Profile", "Account", new { id = model.Id }));
                }
                TempData["errormessage"] = "Address cannot be updated because you did not change anything!";
                return(RedirectToAction("Profile", "Account", new { id = model.Id }));
            }
            return(this.View("Address", model));
        }
        public ActionResult EditPosted(string id, FormCollection posted)
        {
            EditSetup();

            AddressViewModel model = new AddressViewModel();

            if (TryUpdateModel(model))
            {
                CustomerAccount u = MTApp.MembershipServices.Customers.Find(SessionManager.GetCurrentUserId(MTApp.CurrentStore));
                if (u == null)
                {
                    return(View(model));
                }

                Address a = LoadAddress(id);
                model.CopyTo(a);

                string slug = id;
                switch (slug.ToLower())
                {
                case "new":
                    MTApp.MembershipServices.CheckIfNewAddressAndAddWithUpdate(u, a);
                    MTApp.MembershipServices.UpdateCustomer(u);
                    break;

                default:
                    u.UpdateAddress(a);
                    MTApp.MembershipServices.UpdateCustomer(u);
                    break;
                }
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult CreateAddress(AddressViewModel model)
        {
            if (ModelState.IsValid)
            {
                //get account id from cookies
                int id = Convert.ToInt32(User.Claims.Where(c => c.Type == "Id").Select(c => c.Value).SingleOrDefault());

                //copies viewmodel to model
                Address address = model.CopyTo();
                this._account.CreateAddress(address, id);

                TempData["message"] = "Address has been created!";
                return(RedirectToAction("Profile", "Account"));
            }
            return(this.View("Address", model));
        }
Exemplo n.º 4
0
        public ActionResult EditPosted(string id, FormCollection posted)
        {
            var model = new AddressViewModel();

            if (TryUpdateModel(model))
            {
                var u = HccApp.MembershipServices.Customers.Find(HccApp.CurrentCustomerId);
                if (u == null)
                {
                    return(View(model));
                }

                if (model.RegionBvin == "_")
                {
                    model.RegionBvin = string.Empty;
                }

                var addr = LoadAddress(id);
                model.CopyTo(addr);

                var slug = id;
                switch (slug.ToLower())
                {
                case "new":
                    HccApp.MembershipServices.CheckIfNewAddressAndAddWithUpdate(u, addr);
                    HccApp.MembershipServices.UpdateCustomer(u);
                    break;

                default:
                    u.UpdateAddress(addr);
                    HccApp.MembershipServices.UpdateCustomer(u);
                    break;
                }
                return(Redirect(Url.RouteHccUrl(HccRoute.AddressBook)));
            }

            model.Countries = HccApp.GlobalizationServices.Countries.FindActiveCountries();
            var country = HccApp.GlobalizationServices.Countries.Find(model.CountryBvin);

            model.Regions = country.Regions;

            return(View(model));
        }