Esempio n. 1
0
        // GET: /Create
        public ActionResult Create()
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            ViewData["CountryRegions"] = new SelectListItem();

            AddressLocationVM addressLocationVM = new AddressLocationVM();

            Location location = new Location();

            addressLocationVM.Location = location;

            Address address = new Address();

            addressLocationVM.Address = address;

            //StateProvince SelectList
            StateProvinceRepository stateProvinceRepository = new StateProvinceRepository();

            addressLocationVM.StateProvinces = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(address.CountryCode).ToList(), "StateProvinceCode", "Name");

            return(View(addressLocationVM));
        }
Esempio n. 2
0
        // GET: /View
        public ActionResult View(int id)
        {
            //Check Exists
            Location location = new Location();

            location = locationRepository.GetLocation(id);
            if (location == null)
            {
                ViewData["ActionMethod"] = "ViewGet";
                return(View("RecordDoesNotExistError"));
            }

            AddressLocationVM addressLocationVM = new AddressLocationVM();

            addressLocationVM.Location = location;
            addressLocationVM.Address  = new Address();

            Address address = locationRepository.GetLocationAddress(id);

            if (address != null)
            {
                AddressRepository addressRepository = new AddressRepository();
                addressRepository.EditForDisplay(address);
                addressLocationVM.Address = address;
            }

            return(View(addressLocationVM));
        }
Esempio n. 3
0
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Check Exists
            Location location = new Location();

            location = locationRepository.GetLocation(id);
            if (location == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Access Rights
            ViewData["Access"] = "";
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToLocation(id))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            AddressLocationVM addressLocationVM = new AddressLocationVM();

            locationRepository.EditForDisplay(location);
            addressLocationVM.Location = location;

            Address address = locationRepository.GetLocationAddress(id);

            if (address != null)
            {
                AddressRepository addressRepository = new AddressRepository();
                addressRepository.EditForDisplay(address);
                addressLocationVM.Address = address;
            }

            CountryRepository countryRepository = new CountryRepository();
            SelectList        countryRegionList = new SelectList(countryRepository.GetCountryRegions(location.CountryRegion.Country.CountryCode).ToList(), "CountryRegionId", "CountryRegionName");

            ViewData["CountryRegions"] = countryRegionList;

            //StateProvince SelectList
            StateProvinceRepository stateProvinceRepository = new StateProvinceRepository();

            addressLocationVM.StateProvinces = new SelectList(stateProvinceRepository.GetStateProvincesByCountryCode(location.CountryCode).ToList(), "StateProvinceCode", "Name", address.StateProvinceCode);

            return(View(addressLocationVM));
        }
        //Add to DB
        public void Add(AddressLocationVM addressLocationVM)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertLocation_v1(
                addressLocationVM.Location.LocationName,
                addressLocationVM.Location.CountryRegionId,
                addressLocationVM.Address.FirstAddressLine,
                addressLocationVM.Address.SecondAddressLine,
                addressLocationVM.Address.CityName,
                addressLocationVM.Address.StateProvinceCode,
                addressLocationVM.Address.PostalCode,
                addressLocationVM.Address.CountryCode,
                adminUserGuid
                );
        }
Esempio n. 5
0
        public ActionResult Create(AddressLocationVM addressLocationVM)
        {
            //Update  Model from Form
            try
            {
                UpdateModel(addressLocationVM);
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            //Database Update
            try
            {
                locationRepository.Add(addressLocationVM);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            ViewData["NewSortOrder"] = 0;
            return(RedirectToAction("List"));
        }
Esempio n. 6
0
        public ActionResult Edit(AddressLocationVM addressLocationVM)
        {
            //Get Item From Database
            Location location = new Location();

            location = locationRepository.GetLocation(addressLocationVM.Location.LocationId);

            //Check Exists
            if (location == null)
            {
                ViewData["ActionMethod"] = "EditPost";
                return(View("RecordDoesNotExistError"));
            }

            //Access Rights
            ViewData["Access"] = "";
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToLocation(location.LocationId))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Update Item from Form
            try
            {
                UpdateModel(addressLocationVM);
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            //Database Update
            try
            {
                locationRepository.Update(addressLocationVM);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/Location.mvc/Edit/" + location.LocationId.ToString();
                    return(View("VersionError"));
                }

                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            //Success
            return(RedirectToAction("List"));
        }