Пример #1
0
        public JsonResult addUser(user user)
        {
            using (re = new recipeEntities())
            {
                var success = true;
                if (TryUpdateModel(user))
                {
                    re.users.Add(user);
                    //Membership.CreateUser(user.name, user.password);
                    try
                    {
                        //Membership.CreateUser(user.name, user.password, user.email);
                        re.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        // Retrieve the error messages as a list of strings.
                        var errorMessages = ex.EntityValidationErrors
                                .SelectMany(x => x.ValidationErrors)
                                .Select(x => x.ErrorMessage);
                        // Join the list to a single string.
                        var fullErrorMessage = string.Join("; ", errorMessages);
                        // Combine the original exception message with the new one.
                        var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                        // Throw a new DbEntityValidationException with the improved exception message.
                        throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                    }

                }
                else
                {
                    success = false;
                }
                return Json(new { success = success, id = user.id, user = user.getSerialize() }, JsonRequestBehavior.AllowGet);
            }
        }
Пример #2
0
 public ActionResult register(user user)
 {
     if (TryUpdateModel(user))
     {
        // Membership.ValidateUser(user.name, user.password);
         Session["user"] = user;
     }
     else
         Session["user"] = null;
     return Json("success", JsonRequestBehavior.AllowGet);
 }