Example #1
0
        public ActionResult Edit(string id, int locationId, FormCollection collection)
        {
            SystemUser systemUser = new SystemUser();

            systemUser = systemUserRepository.GetUserBySystemUserGuid(id);

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

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

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


            SystemUser originalSystemUser = new SystemUser();

            originalSystemUser = systemUserRepository.GetUserBySystemUserGuid(id);

            //CubaBookingAllowanceIndicator with Logging
            bool cubaBookingAllowanceIndicator = false;

            if (originalSystemUser.CubaBookingAllowanceIndicator == true)
            {
                cubaBookingAllowanceIndicator = true;
            }

            //MilitaryAndGovernmentUserFlag with Logging
            bool militaryAndGovernmentUserFlag = false;

            if (originalSystemUser.MilitaryAndGovernmentUserFlag == true)
            {
                militaryAndGovernmentUserFlag = true;
            }

            //Update Item from Form
            try
            {
                UpdateModel(systemUser);
            }
            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
            {
                systemUserRepository.Edit(systemUser);

                //Edit SystemUser CubaBookingAllowanceIndicator
                if (cubaBookingAllowanceIndicator != systemUser.CubaBookingAllowanceIndicator)
                {
                    systemUser.VersionNumber = systemUser.VersionNumber + 1;
                    systemUserRepository.EditCubaBookingAllowanceIndicator(systemUser);
                }

                //Edit SystemUser MilitaryAndGovernmentUserFlag
                if (militaryAndGovernmentUserFlag != systemUser.MilitaryAndGovernmentUserFlag)
                {
                    systemUser.VersionNumber = systemUser.VersionNumber + 1;
                    systemUserRepository.EditMilitaryAndGovernmentUserFlag(systemUser);
                }
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/SystemUser.mvc/Edit?id=" + systemUser.SystemUserGuid;
                    return(View("VersionError"));
                }

                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"));
        }