Пример #1
0
        public async Task <IActionResult> Create(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new Userss
                {
                    UserName     = model.Email,
                    PasswordHash = model.Password,
                    FullName     = model.Full_Name
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                //await _usersService.AddAndSave(user);
                //return RedirectToAction(nameof(Index));
                if (result.Succeeded)
                {
                    return(RedirectToAction("index", "/Userss"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            return(View(model));
        }
Пример #2
0
        public ActionResult Detail(int id)
        {
            if (Session["user"] == null)
            {
                return(Redirect("~/Home/Index"));
            }
            Userss User = (Userss)Session["user"];

            if (User.UserType != 1)
            {
                return(Redirect("~/Home/Index"));
            }

            var          result = db.Products.Find(id);
            ProductModel model  = new ProductModel();

            if (result != null)
            {
                model.ProductID   = result.ProductID;
                model.Name        = result.Name;
                model.PictureName = result.PictureName;
                model.Price       = result.Price;
                model.Description = result.Description;
                model.CategoryID  = result.CategoryID;
                model.IsActive    = result.IsActive;
                model.CreatedOn   = result.CreatedOn;
                model.ModifiedOn  = result.ModifiedOn;
            }
            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("User_id,Username,Password,FullName,Role_id")]  Userss book)
        {
            if (id != book.User_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BooksExists(book.User_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["Role_id"] = new SelectList(_context.Roles, "id", "id", book.Role_id);
            return(View(book));
        }
Пример #4
0
        public ActionResult Edit(int id)
        {
            if (Session["user"] == null)
            {
                return(Redirect("~/Home/Index"));
            }
            Userss User = (Userss)Session["user"];

            if (User.UserType != 1)
            {
                return(Redirect("~/Home/Index"));
            }

            var          prod  = db.Products.Find(id);
            ProductModel model = new ProductModel();

            if (prod != null)
            {
                model.ProductID   = prod.ProductID;
                model.Name        = prod.Name;
                model.Description = prod.Description;
                model.PictureName = prod.PictureName;
                model.Price       = prod.Price;
                model.CreatedOn   = prod.CreatedOn;
                model.ModifiedOn  = prod.ModifiedOn;
                model.IsActive    = prod.IsActive;
                model.CategoryID  = prod.CategoryID;
            }
            return(View("New", model));
        }
Пример #5
0
        public ActionResult New()
        {
            if (Session["user"] == null)
            {
                return(Redirect("~/Home/Index"));
            }
            Userss User = (Userss)Session["user"];

            if (User.UserType != 1)
            {
                return(Redirect("~/Home/Index"));
            }

            var list = db.Categories.ToList();
            List <SelectListItem> cList = new List <SelectListItem>();

            foreach (Category c in list)
            {
                cList.Add(new SelectListItem {
                    Value = Convert.ToString(c.CategoryID), Text = c.CategoryName
                });
            }

            ViewBag.CategoryList = cList;

            return(View(new ProductModel()));
        }
Пример #6
0
        public ActionResult Index()
        {
            if (Session["user"] == null)
            {
                return(Redirect("~/Home/Index"));
            }
            Userss User = (Userss)Session["user"];

            if (User.UserType != 1)
            {
                return(Redirect("~/Home/Index"));
            }

            var products = db.Products.ToList();
            List <ProductModel> productList = new List <ProductModel>();

            foreach (Product item in products)
            {
                if (item.IsActive == 1)
                {
                    productList.Add(new ProductModel
                    {
                        ProductID   = item.ProductID,
                        Name        = item.Name,
                        Description = item.Description,
                        Price       = item.Price,
                        PictureName = item.PictureName
                    });
                }
            }
            return(View(productList));
        }
Пример #7
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Copy data from RegisterViewModel to IdentityUser
                var user = new Userss
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    FullName = model.Full_Name,
                };

                // Store user data in AspNetUsers database table
                var result = await userManager.CreateAsync(user, model.Password);

                // If user is successfully created, sign-in the user using
                // SignInManager and redirect to index action of HomeController
                if (result.Succeeded)
                {
                    return(RedirectToAction("index", "/"));
                }

                // If there are any errors, add them to the ModelState object
                // which will be displayed by the validation summary tag helper
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            return(View(model));
        }
Пример #8
0
        public async Task <IActionResult> Update(string id, [Bind("User_id,Username,Password,FullName")]  Userss user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _service.UpdateAndSave(user);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_service.UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["RoomId"] = new SelectList(await _service.GetAllRoles(), "Role_id", "Role_id", user.Role_id);
            return(View(user));
        }
Пример #9
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName,UserEmail,UserPassword,Created,UserStatus")] Userss userss)
        {
            if (id != userss.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userss);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserssExists(userss.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userss));
        }
Пример #10
0
        public ActionResult Registrar(RegistrationModel userss)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (DbContextShop dbCtx = new DbContextShop())
                    {
                        //var duplicate = dbCtx.Usersses.Any(x => x.UserName == userss.UserName);
                        //if (duplicate)
                        //{
                        //    ModelState.AddModelError("UserName", "Ya existe una persona con ese UserName");
                        //}
                        //else
                        //{
                        int row = dbCtx.Usersses.Count();
                        if (row > 0)
                        {
                            Userss us = new Userss()
                            {
                                LastName  = userss.LastName,
                                FirstName = userss.FirstName,
                                Email     = userss.Email,
                                UserName  = userss.UserName,
                                Password  = EncryptionDecryption.EncriptarSHA1(userss.Password)
                            };
                            dbCtx.Usersses.Add(us);
                            dbCtx.SaveChanges();
                            var          path     = Server.MapPath("~") + @"Files";
                            var          fileName = "/Log2.txt";
                            StreamWriter sw       = new StreamWriter(path + fileName, true);
                            sw.WriteLine("Metodo Registrar -" + DateTime.Now + "Se registró el cliente: " + userss.FirstName + " " + userss.LastName);
                            sw.Close();

                            return(RedirectToAction("Index", "Image"));
                        }
                        //}
                    }
                }
            }
            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);
            }

            return(View(userss));
        }
        public int AddUser(Userss entity)
        {
            Userss mModel = new Userss();
            Role   rModel = new Role();

            userRepository.Insert(entity);
            return(1);
        }
Пример #12
0
        //登录管理员信息JJ
        public Userss UsersDeng(Userss u)
        {
            string sql = $"select Uid,Uname from Users where Uname='{u.Uname}' and Upwd='{u.Upwd}'";
            var    dt  = DBHelper.ExecuteQuery(sql, System.Data.CommandType.Text);
            string str = JsonConvert.SerializeObject(dt);
            Userss uu  = JsonConvert.DeserializeObject <List <Userss> >(str).FirstOrDefault();

            return(uu);
        }
Пример #13
0
        //反填用户信息
        public Userss UsersFan(int Id)
        {
            string sql = $"select * from Users where Uid={Id}";
            var    dt  = DBHelper.ExecuteQuery(sql, System.Data.CommandType.Text);
            string str = JsonConvert.SerializeObject(dt);
            Userss u   = JsonConvert.DeserializeObject <List <Userss> >(str).FirstOrDefault();

            return(u);
        }
Пример #14
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            using (MD5 md5hash = MD5.Create())
            {
                string hashPass = HashMD5(md5hash, RegisterUser.Password.Trim()); // haslo zahashowane

                heartbaseEntities db = new heartbaseEntities();                   // zapis parametrow z formularza
                // string name = Request.Form[6];

                Userss us = new Userss
                {
                    Username = RegisterUser.UserName.Trim(),
                    Password = hashPass,
                    Email    = RegisterUser.Email.Trim(),
                    Name     = Request.Form[6].ToString(), //RegisterUser.Name.Trim(),
                    Surname  = Request.Form[7].ToString()
                                                           //Name = "name",
                                                           //Surname = "surname"
                };

                db.Userss.Add(us);
                db.SaveChanges();



                /*
                 * int ID = 0;
                 * string connStr = ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString;
                 * using (SqlConnection conn = new SqlConnection(connStr))
                 * {
                 *  using (SqlCommand cmd = new SqlCommand())
                 *  {
                 *      //using (SqlDataAdapter sda = new SqlDataAdapter())
                 *      //{
                 *      //    cmd.CommandType = CommandType.StoredProcedure;
                 *      //    cmd.Parameters.AddWithValue("@Username", RegisterUser.UserName.Trim());
                 *      //    cmd.Parameters.AddWithValue("@Password", hashPass);
                 *      //    cmd.Parameters.AddWithValue("@Email", RegisterUser.Email.Trim());
                 *      //    cmd.Connection = conn;
                 *      //    conn.Open();
                 *      //    ID = Convert.ToInt32(cmd.ExecuteScalar());
                 *      //    conn.Close();
                 *      //}
                 *
                 *      cmd.CommandText = "select * from Userss";
                 *      cmd.Connection = conn;
                 *      cmd.CommandType = CommandType.TableDirect
                 *
                 *
                 *
                 *  }
                 *  SendActivationEmail(ID);
                 * }
                 */
            }
        }
Пример #15
0
 public void AddUser(Userss user)
 {
     if (ListWithUsers.Any(n => n.name == user.name))
     {
         Console.WriteLine("Error!!! This user already exists");
     }
     else
     {
         ListWithUsers.Add(user);
     }
 }
Пример #16
0
        public async Task <IActionResult> Register([Bind("UserId,UserName,UserEmail,UserPassword,Created,UserStatus")] Userss userss)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userss);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userss));
        }
Пример #17
0
        //修改用户状态
        public int UsersZt(Userss u)
        {
            string sql = "";

            if (u.UZt == "正常")
            {
                sql = $"update Users set UZt='禁用' where Uid={u.Uid}";
            }
            else
            {
                sql = $"update Users set UZt='正常' where Uid={u.Uid}";
            }
            return(DBHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text));
        }
Пример #18
0
        public bool add(Modelo prEntity)
        {
            try
            {
                User Entity = (User)prEntity;

                Userss.Add(Entity);

                return(SaveChanges() > 0);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #19
0
        public ActionResult Login(LoginModel loginModel)
        {
            Userss user            = new Userss();
            ReflectionsEntities db = new ReflectionsEntities();

            user = db.Usersses.FirstOrDefault(us => us.UserName.Equals(loginModel.UserName) && us.Password.Equals(loginModel.Password));

            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(user.UserName, false);
                Session["User"] = user;
                return(RedirectToAction("List", "Employee"));
            }
            return(View());
        }
Пример #20
0
        public IActionResult Create([Bind("User_id,Username,Password,FullName,Role_id")] Userss user)
        {
            if (_context.Userss.Any(x => x.Username == user.Username))
            {
                ModelState.AddModelError("Username", "Username already in use");
            }
            if (ModelState.IsValid)
            {
                _context.Userss.Add(user);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewData["Role_id"] = new SelectList(_context.Roles, "User_id", "Role_id", user.Role_id);
            return(View(user));
        }
Пример #21
0
        public ActionResult Mod(string user, Userss userss)
        {
            user = Convert.ToString(Session["UserName"]);
            if (Session["UserName"] != null)
            {
                var en = dbCtx.Usersses.Find(userss.UserID);

                dbCtx.Entry(en).State = EntityState.Modified;
                dbCtx.SaveChanges();

                return(RedirectToAction("Index", "Image"));
            }
            else
            {
                return(View());
            }
        }
Пример #22
0
        public ActionResult Register(UserModel user)
        {
            if (ModelState.IsValid)
            {
                var uniqueName = "";
                if (Request.Files["image"] != null)
                {
                    var file = Request.Files["image"];
                    if (file.FileName != "")
                    {
                        var ext = System.IO.Path.GetExtension(file.FileName);
                        uniqueName = Guid.NewGuid().ToString() + ext;
                        var rootPath     = Server.MapPath("~/Images/Users");
                        var fileSavePath = System.IO.Path.Combine(rootPath, uniqueName);

                        file.SaveAs(fileSavePath);
                        user.PictureName = uniqueName;
                    }
                }

                Userss dto = new Userss();

                dto.FirstName   = user.FirstName;
                dto.LastName    = user.LastName;
                dto.Email       = user.Email.ToLower();
                dto.Mobile      = user.Mobile;
                dto.Password    = user.Password;
                dto.PictureName = user.PictureName;
                dto.UserType    = 2;
                dto.IsActive    = 1;
                dto.CreatedOn   = DateTime.Now;
                dto.Address1    = user.Address1;
                dto.Address2    = user.Address2;
                dto.Gender      = user.Gender;

                var db = new ShoppingWebsiteEntities();

                db.Userss.Add(dto);
                db.SaveChanges();
                Session["user"] = dto;
                return(Redirect("~/Home/Index"));
            }


            return(View(user));
        }
Пример #23
0
        public bool update(Modelo prEntity)
        {
            try
            {
                User Entity = (User)prEntity;

                User lUser = Userss.Find(Entity.userid);

                if (lUser != null && lUser != Entity)
                {
                    lUser.Update(Entity);
                }

                return(SaveChanges() > 0);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #24
0
        public bool delete(Modelo prEntity)
        {
            try
            {
                User Entity = (User)prEntity;

                Userss.Attach(Entity);

                if (Entry(Entity).State == EntityState.Detached)
                {
                    Userss.Attach(Entity);
                }

                Userss.Remove(Entity);

                return(SaveChanges() > 0);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #25
0
        public ActionResult Delete(int id)
        {
            if (Session["user"] == null)
            {
                return(Redirect("~/Home/Index"));
            }
            Userss User = (Userss)Session["user"];

            if (User.UserType != 1)
            {
                return(Redirect("~/Home/Index"));
            }

            var result = db.Products.Find(id);

            if (result != null)
            {
                result.IsActive   = 0;
                result.ModifiedOn = DateTime.Now;
                db.SaveChanges();
            }
            TempData["Msg"] = "Product Deleted Successfully";
            return(RedirectToAction("Index", "Product"));
        }
Пример #26
0
        //修改用户信息
        public int UsersUpd(Userss u)
        {
            string sql = $"update Users set Uname='{u.Uname}',UZhangHao='{u.UZhangHao}',Upwd='{u.Upwd}' where Uid={u.Uid}";

            return(DBHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text));
        }
Пример #27
0
 public void AddUser(Userss user) => UserStorage.AddUser(user);
Пример #28
0
        //添加用户信息
        public int UsersAdd(Userss u)
        {
            string sql = $"insert into Users(Uname,UZhangHao,Upwd) values('{u.Uname}','{u.UZhangHao}','{u.Upwd}')";

            return(DBHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text));
        }
Пример #29
0
        public ActionResult New(ProductModel product)
        {
            if (Session["user"] == null)
            {
                return(Redirect("~/Home/Index"));
            }
            Userss User = (Userss)Session["user"];

            if (User.UserType != 1)
            {
                return(Redirect("~/Home/Index"));
            }

            if (ModelState.IsValid)
            {
                var uniqueName = "";
                if (Request.Files["image"] != null)
                {
                    var file = Request.Files["image"];
                    if (file.FileName != "")
                    {
                        var ext = System.IO.Path.GetExtension(file.FileName);
                        uniqueName = Guid.NewGuid().ToString() + ext;
                        var rootPath     = Server.MapPath("~/Images");
                        var fileSavePath = System.IO.Path.Combine(rootPath, uniqueName);

                        file.SaveAs(fileSavePath);
                        product.PictureName = uniqueName;
                    }
                }

                Product prod = null;
                if (product.ProductID != 0)
                {
                    prod = db.Products.Find(product.ProductID);
                    if (prod != null)
                    {
                        prod.Name        = product.Name;
                        prod.Description = product.Description;
                        prod.Price       = product.Price;
                        prod.PictureName = product.PictureName;
                        prod.ModifiedOn  = DateTime.Now;
                    }

                    TempData["Msg"] = "Product Updated Successfully";
                }
                else
                {
                    prod             = new Product();
                    prod.Name        = product.Name;
                    prod.Description = product.Description;
                    prod.Price       = product.Price;
                    prod.PictureName = product.PictureName;
                    prod.CreatedOn   = DateTime.Now;
                    prod.IsActive    = 1;
                    prod.CategoryID  = product.CategoryID;
                    TempData["Msg"]  = "Product Created Successfully";
                    db.Products.Add(prod);
                }

                db.SaveChanges();

                return(Redirect("Index"));
            }
            var list = db.Categories.ToList();
            List <SelectListItem> cList = new List <SelectListItem>();

            foreach (Category c in list)
            {
                cList.Add(new SelectListItem {
                    Value = Convert.ToString(c.CategoryID), Text = c.CategoryName
                });
            }

            ViewBag.CategoryList = cList;
            return(View(new ProductModel()));
        }
Пример #30
0
 public IActionResult Update_Post(Userss book)
 {
     _context.Userss.Update(book);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }