Пример #1
0
        public ActionResult UpdateUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var db = new eXmlContext())
                    {
                        var user = db.Set<User>()
                            .SingleOrDefault(x => x.UserId == model.UserId);

                        user.Email = model.Email;
                        user.Password = model.Password;
                        user.IsLicensed = model.IsLicensed;
                        user.ExpiryDate = model.ExpiryDate;

                        db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }

            }
            else
            {
                ViewData["EditError"] = "Please correct all errors";
                ViewData["User"] = model;
            }
            return PartialView("_GridListUsers", AdminServiceProvider.Users());
        }
Пример #2
0
        public ActionResult AddUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                string cryptoKey = ConfigurationManager.AppSettings["CryptoKey"].ToString();
                Crypto.Key = cryptoKey;
                Crypto.EncryptionAlgorithm = Crypto.Algorithm.DES;
                
                try
                {
                    string encryptPwd ="" ;
                    if (Crypto.EncryptString(model.Password))
                    {
                       
                        encryptPwd = Crypto.Content;
                    }
                    User u = new User
                    {
                        Email = model.Email,
                        Password = encryptPwd,
                        IsLicensed = model.IsLicensed,
                        ExpiryDate = model.ExpiryDate
                    };

                    using (var db = new eXmlContext())
                    {
                        db.Users.Add(u);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }

            else
            {
                ViewData["EditError"] = "Please correct all errors";
                ViewData["User"] = model;
            }
            return PartialView("_GridListUsers",AdminServiceProvider.Users());
        }