Пример #1
0
        public ActionResult Edit(ServiceFundVM serviceFundVM, FormCollection formCollection)
        {
            //Get Item
            ServiceFund serviceFund = new ServiceFund();

            serviceFund = serviceFundRepository.GetServiceFund(serviceFundVM.ServiceFund.ServiceFundId);

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

            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Convert Times to DateTime for DB
            serviceFund.ServiceFundStartTime = CWTStringHelpers.BuildDateTime(serviceFundVM.ServiceFund.ServiceFundStartTimeString);
            serviceFund.ServiceFundEndTime   = CWTStringHelpers.BuildDateTime(serviceFundVM.ServiceFund.ServiceFundEndTimeString);

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <ServiceFund>(serviceFund, "ServiceFund");
            }
            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
            {
                serviceFundRepository.Edit(serviceFund);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/ServiceFund.mvc/Edit/" + serviceFund.ServiceFundId;
                    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"));
            }

            return(RedirectToAction("List"));
        }
        public ActionResult Edit(int id, DateTime OpeningDateTime, int WeekDayId, DateTime OpeningDateTimeOriginal, int WeekDayIdOriginal, FormCollection collection)
        {
            //Check Exists
            LocalOperatingHoursItem localOperatingHoursItemOriginal = localOperatingHoursRepository.GetItem(id, WeekDayIdOriginal, OpeningDateTimeOriginal);

            if (localOperatingHoursItemOriginal == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }
            if (localOperatingHoursItemOriginal != null)
            {
                try
                {
                    localOperatingHoursRepository.Delete(localOperatingHoursItemOriginal);
                }
                catch (SqlException ex)
                {
                    //Versioning Error - go to standard versionError page
                    if (ex.Message == "SQLVersioningError")
                    {
                        ViewData["ReturnURL"] = "/LocalOperatingHoursItem.mvc/Edit/" + localOperatingHoursItemOriginal.LocalOperatingHoursGroupId;
                        return(View("VersionError"));
                    }
                    //Generic Error
                    ViewData["Message"] = "Unknown DBError";
                    return(View("Error"));
                }
            }

            //New Item
            LocalOperatingHoursItem localOperatingHoursItem = new LocalOperatingHoursItem();

            //Update Model from Form
            try
            {
                UpdateModel(localOperatingHoursItem);
            }
            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"));
            }

            //Convert Times to DateTime for DB
            localOperatingHoursItem.OpeningDateTime = CWTStringHelpers.BuildDateTime(localOperatingHoursItem.OpeningTime);
            localOperatingHoursItem.ClosingDateTime = CWTStringHelpers.BuildDateTime(localOperatingHoursItem.ClosingTime);

            try
            {
                localOperatingHoursRepository.Add(localOperatingHoursItem);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/LocalOperatingHoursItem.mvc/Edit/" + localOperatingHoursItem.LocalOperatingHoursGroupId;
                    return(View("VersionError"));
                }
                //Generic Error
                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }
            //Return To List
            return(RedirectToAction("List", new { id = localOperatingHoursItem.LocalOperatingHoursGroupId }));
        }
Пример #3
0
        public ActionResult Create(ServiceFundVM serviceFundVM, FormCollection formCollection)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //We need to extract group from groupVM
            ServiceFund serviceFund = new ServiceFund();

            serviceFund = serviceFundVM.ServiceFund;
            if (serviceFund == null)
            {
                ViewData["Message"] = "ValidationError : missing item";;
                return(View("Error"));
            }

            //Convert Times to DateTime for DB
            serviceFund.ServiceFundStartTime = CWTStringHelpers.BuildDateTime(serviceFund.ServiceFundStartTimeString);
            serviceFund.ServiceFundEndTime   = CWTStringHelpers.BuildDateTime(serviceFund.ServiceFundEndTimeString);

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel <ServiceFund>(serviceFund, "ServiceFund");
            }
            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
            {
                serviceFundRepository.Add(serviceFund);
            }
            catch (SqlException ex)
            {
                //Non-Unique Name
                if (ex.Message == "NonUniqueName")
                {
                    return(View("NonUniqueNameError"));
                }

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