Пример #1
0
        public ActionResult Create(AspnetUsers user, string[] selectedObjects, bool isAdministrator)
        {
            // Note checkboxes require special handling in mvc
            // Posts Render an additional <input type="hidden".../> for checkboxes if checked which provides a true and false value.
            // This addresses scenarios where unchecked checkboxes are not sent in the request. 
            // Sending a hidden input makes it possible to know that the checkbox 
            // was present on the page when the request was submitted.
            // as a result of this querying formas parameters produces unexpected results. The workaround institued for
            // this problem takes account that only checkboxes which are selected/changed in selected Objects as passed.
            // Inspect the key value to work out what has changed.       
            try
            {
                IUnitOfWorkFactory factory = new WebSiteUnitOfWorkFactory();
                IAspNetUnitOfWork unitOfWork = factory.GetAspNetUnitOfWork();

                List<CheckBoxListInfo> checkBoxListItems = GetCheckedBoxes(selectedObjects);
                ViewData["listItems"] = checkBoxListItems;
                           
                user = unitOfWork.Save(user, isAdministrator, selectedObjects);

                return RedirectToAction("Index");
            }
            catch (RuleException ex)
            {
                ex.CopyToModelState(ModelState);
                return View();
            }
            catch (Exception ex)
            {
                RuleException rex = new RuleException("error", ex.Message);
                rex.CopyToModelState(ModelState);
                return View();
            }
        }
Пример #2
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns>The view instance.</returns>
        public ActionResult Create()
        {
            List<CheckBoxListInfo> checkBoxListItems = PopulateCheckBoxesForCreate();

            ViewData["listItems"] = checkBoxListItems;
            AspnetUsers user = new AspnetUsers();
            return View(user);
        }
Пример #3
0
        public ActionResult Edit(
            string userId,           
            string submitButton, 
            AspnetUsers user,
            bool isAdministrator, 
            string[] selectedObjects, 
            FormCollection collection)            
        {
            try
            {
                // Note checkboxes require special handling in mvc
                // Posts Render an additional <input type="hidden".../> for checkboxes if checked which provides a true and false value.
                // This addresses scenarios where unchecked checkboxes are not sent in the request. 
                // Sending a hidden input makes it possible to know that the checkbox 
                // was present on the page when the request was submitted.
                // as a result of this querying formas parameters produces unexpected results. The workaround institued for
                // this problem takes account that only checkboxes which are selected/changed in selected Objects as passed.
                // Inspect the key value to work out what has changed.       
                IUnitOfWorkFactory factory = new WebSiteUnitOfWorkFactory();
                IAspNetUnitOfWork unitOfWork = factory.GetAspNetUnitOfWork();

                switch (submitButton)
                {
                    case "Save":
                        ViewData["userWebSites"] = GetUserWebSitesWithDefaultDetails();                      
                        user = unitOfWork.Save(user, isAdministrator, selectedObjects);
                        return RedirectToAction("Index");
                    case "Delete":                      
                        unitOfWork.Delete(user);
                        return RedirectToAction("Index");
                    default:
                        // If they've submitted the form without a submitButton,  
                        // just return the view again. 
                        return RedirectToAction("View");
                }
            }
            catch (Exception ex)
            {
                RuleException rex = new RuleException("error", ex.Message);
                rex.CopyToModelState(ModelState);
                return View();
            }
        }