Exemplo n.º 1
0
        public IActionResult Post([FromBody] Product entity)
        {
            IActionResult ret = null;

            try
            {
                //using (var db = new LoginDbContext())
                //{
                if (entity != null)
                {
                    db.Products.Add(entity);
                    db.SaveChanges();
                    ret = StatusCode(StatusCodes.Status201Created,
                                     entity);
                }
                else
                {
                    ret = StatusCode(StatusCodes.Status400BadRequest, "Invalid object passed to POST method");
                }
                //  }
            }
            catch (Exception ex)
            {
                ret = HandleException(ex, "Exception trying to insert a new product");
            }

            return(ret);
        }
Exemplo n.º 2
0
 public void Registreerimine(string Login, string Password)
 {
     using (LoginDbContext _context = new LoginDbContext())
     {
         LoginTable loginTable = new LoginTable()
         {
             Name = Login
         };
         if (!string.IsNullOrEmpty(Login) || !string.IsNullOrEmpty(Password))
         {
             string _salt = CreateSalt(10);
             loginTable.Salt = _salt;
             loginTable.Hash = GenerateSHA256Hash(Password, _salt);
             try
             {
                 _context.LoginTable.Add(loginTable);
                 _context.SaveChanges();
                 _service.MessageInfo("Registreeritud", "Info");
             }
             catch (Exception ex)
             {
                 _service.MessageError(ex.Message, "Viga");
             }
         }
         else
         {
             _service.MessageExclamation("Sisestage andmed!", "Sõnum");
         }
     }
 }
Exemplo n.º 3
0
        public IActionResult Delete(int id)
        {
            var user = _context.Users.FirstOrDefault(x => x.Id == id);

            _context.Users.Remove(user);
            _context.SaveChanges();
            return(View("List", _userManager.Users));
        }
Exemplo n.º 4
0
        public IActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Person newPerson = new Person
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Email       = model.Email,
                    IsEmployee  = model.IsEmployee,
                    Address     = model.Address,
                    City        = model.City,
                    DateOfBirth = model.DateOfBirth,
                    IsOutsorced = model.IsOutsorced,
                    IsVolunteer = model.IsVolunteer,
                    PIN         = model.PIN
                };


                _context.Persons.Add(newPerson);
                _context.SaveChanges();

                User newUser = new User
                {
                    Password = model.Password,
                    Login    = model.Login,
                    PersonId = newPerson.ID
                };

                PasswordHasher <User> hasher = new PasswordHasher <User>();
                newUser.Password = hasher.HashPassword(newUser, newUser.Password);

                _context.Users.Add(newUser);

                _context.SaveChanges();



                return(RedirectToAction("Login"));
            }
            //tu treba greska
            return(View("Index"));
        }
Exemplo n.º 5
0
 public ActionResult Register(UserAccount account)
 {
     if (ModelState.IsValid)
     {
         using (LoginDbContext db = new LoginDbContext())
         {
             db.UserAccount.Add(account);
             db.SaveChanges();
         }
         // for clear the context of all input controls
         ModelState.Clear();
         ViewBag.Message = account.FirstName + " " + account.LastName + " successfully registered.";
     }
     return(View());
 }
Exemplo n.º 6
0
        public ActionResult TestAdd([Bind(Include = "UserName,Password,IsActive,UserId")] LoginModel model)   //没有Bind进来的字段就添加不进去数据库,
        {
            LoginDbContext db = new LoginDbContext();

            LoginModel loginModel = new LoginModel()
            {
                UserId   = model.UserId, //userID设置为了Key,既主键,EF会自动增长,这里添加的话,也不会报错。如果有UserID为1的记录我在添加也不会报错。加进去是递增的,是EF自动增长决定的,和模型绑定无关。
                UserName = model.UserName,
                Password = model.Password,
                IsActive = model.IsActive
            };

            db.LoginModel.Add(loginModel);
            db.SaveChanges();
            return(RedirectToAction("Login"));
        }
Exemplo n.º 7
0
 public JsonResult Register(UserRegister model)
 {
     using (LoginDbContext db = new LoginDbContext())
     {
         if (db.UserRegisters.Where(a => (a.UserName == model.UserName)).Count() > 0)
         {
             return(Json(new { result = "error", content = "注册失败,用户名已经存在" }));
         }
         if (db.UserRegisters.Where(a => a.UserEmail == model.UserEmail).Count() > 0)
         {
             return(Json(new { result = "error", content = "注册失败,邮箱已经存在" }));
         }
         db.UserRegisters.Add(model);
         db.SaveChanges();
         return(Json(new { result = "success", content = "注册成功 欢迎你:" + model.UserName }));
     }
 }
        public ActionResult Registration(User model)
        {
            try
            {
                using (var db = new LoginDbContext())
                {
                    User user = db.Users.Where(s => s.UserName == model.UserName || s.EmailId == model.EmailId).FirstOrDefault();
                    if (user == null)
                    {
                        //产生加密的盐
                        var keyNew = EncryptionHelper.GeneratePassword(10);
                        //加密密码
                        var password = EncryptionHelper.EncodePassword(model.Password, keyNew);

                        //将加密之后的密码保存到数据库
                        model.Password   = password;
                        model.CreateDate = DateTime.Now;
                        model.ModifyDate = DateTime.Now;
                        //盐
                        model.VCode = keyNew;
                        db.Users.Add(model);
                        db.SaveChanges();
                        //返回到登陆页面
                        return(RedirectToAction("Login", "Login"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "User Allredy Exixts!!!!!!!!!!";
                        return(View());
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "Some exception occured" + ex;
                return(View());
            }
        }
Exemplo n.º 9
0
 public int Complete()
 {
     return(m_dbContext.SaveChanges());
 }