Ejemplo n.º 1
0
        protected ActionResult ProcessForm(Models.Person record)
        {
            try {
                Web.InfoMessage = null;
                record.UpdateFromRequest();

                if (record.Password.IsBlank())
                {
                    record.Password = Beweb.RandomPassword.Generate(8);
                }

                Validate(record);

                if (ModelState.IsValid)
                {
                    Save(record, record.IsNewRecord);

                    if (Web.Request["sendemail"] != null)
                    {
                        ProcessEmail(record);
                    }

                    Web.InfoMessage = "Person " + record.GetName() + " saved." + TempData["emailMsg"];
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("PersonEdit", record));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.Person();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage = "Copy of Person " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
Ejemplo n.º 2
0
 private void Save(Models.Person record, bool isNew)
 {
     // add any code to update other fields/tables here
     if (Request["pwValue"] + "" != "")
     {
         record.Password = Security.CreateSecuredPassword(Request["pwValue"]);
     }
     if (record.Password.IsBlank())
     {
         // Person MUST have a password
         record.Password = Beweb.RandomPassword.Generate(8);;
     }
     record.Save();
     PersonCache.Rebuild();
 }