Esempio n. 1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            //{
            //    return RedirectToLocal(returnUrl);
            //}
            if (Session["admin_User"] != null)
            {
                LoginModel m = Session["admin_User"] as LoginModel;
                if (m != null && m.UserName == "admin")
                {
                    RedirectToRoute(new { controller = "ProductType", action = "Index", area = "Admin" });
                }
            }
            object pwd = BUsers.ExecuteSql("select password from Users where userName='******'");

            if (pwd == null)
            {
                return(View());
            }
            string inputPwd = MyEncrypt.MD5Encrypt(model.Password);

            if (inputPwd == pwd.ToString())
            {
                Session["admin_User"] = model;
                return(RedirectToRoute(new { controller = "ProductType", action = "Index", area = "Admin" }));
            }
            else
            {
                // 如果我们进行到这一步时某个地方出错,则重新显示表单
                ModelState.AddModelError("", "提供的用户名或密码不正确。");
            }
            return(View(model));
        }
Esempio n. 2
0
        protected void ButUpdateUser_Click(object sender, EventArgs e)
        {
            // Gets people index from ViewState
            users = (DataLibrary.Users)ViewState["users"];

            // Set user

            users.Name     = boxName.Text;
            users.LastName = boxLastName.Text;
            users.RegionId = Convert.ToInt32(DdlRegion.SelectedValue);

            DateTime signDate = DateTime.ParseExact(boxSignUp.Text, "dd/MM/yyyy", null);

            users.SignUpDate = Convert.ToDateTime(signDate);
            DateTime renewDate = DateTime.ParseExact(boxRenewal.Text, "dd/MM/yyyy", null);

            users.RenewalDate = Convert.ToDateTime(renewDate);

            users.UserName = boxUserName.Text;
            users.Pass     = boxPass.Text;

            BUsers.update(users);

            Response.Redirect("~/Users/MainList.aspx");
        }
Esempio n. 3
0
        public ActionResult CreateOrEdit(UserModel model)
        {
            BUsers user = AutoMapper <UserModel, BUsers> .Map(model);

            userService.CreateOrUpdate(user);
            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        // End declaration

        protected void Page_Load(object sender, EventArgs e)
        {
            // It does this only the first time the page is loaded
            if (!IsPostBack)
            {
                // Get user index and usert object for that index
                userIndex = Convert.ToInt32(Request.QueryString["userId"]);
                users     = BUsers.getById(userIndex);

                // Save the user object in viewState
                ViewState["users"] = users;


                // Load the dropDownList
                DdlRegion.DataSource     = BRegions.getAll();
                DdlRegion.DataTextField  = "Name";
                DdlRegion.DataValueField = "RegionId";
                DdlRegion.DataBind();

                // DNI cannot be modified
                boxDNI.Enabled = false;
                boxDNI.Text    = users.Dni.ToString();

                // Set the value of the record
                DdlRegion.SelectedValue = users.RegionId.ToString();
                boxName.Text            = users.Name;
                boxLastName.Text        = users.LastName;

                boxSignUp.Text   = users.SignUpDate.ToString("dd/MM/yyyy");
                boxRenewal.Text  = users.RenewalDate.ToString("dd/MM/yyyy");
                boxUserName.Text = users.UserName;
                boxPass.Text     = users.Pass;
            }
        }
        protected void ButInsertUser_Click(object sender, EventArgs e)
        {
            //Set the renewal day
            boxRenewal.Enabled = false;

            //boxRenewal.Text = DateTime.Today.AddMonths(6).ToShortDateString();

            // Set users
            users.UserName = boxUserName.Text;
            users.Pass     = boxPass.Text;

            DateTime signD = DateTime.ParseExact(boxSignUp.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            users.SignUpDate = signD;
            DateTime renewD = DateTime.ParseExact(boxRenewal.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            renewD            = DateTime.Today.AddMonths(6);
            users.RenewalDate = renewD;

            users.Name     = boxName.Text;
            users.LastName = boxLastName.Text;
            users.RegionId = Convert.ToInt32(DdlRegion.SelectedValue);
            users.Dni      = Convert.ToInt32(boxDNI.Text);

            try
            {
                BUsers.insert(users);
                Response.Redirect("~/Users/MainList.aspx");
            }
            catch (Exception generalException)
            {
                PanelInsertUser.Visible = true;
                LiteralInsertUser.Text  = generalException.Message;
            }
        }
Esempio n. 6
0
        // End declaration

        protected void Page_Load(object sender, EventArgs e)
        {
            // It does this only the first time the page is loaded
            if (!IsPostBack)
            {
                // Get the record to update through the index in the url
                userIndex = Convert.ToInt32(Request.QueryString["userId"]);
                users     = BUsers.getById(userIndex);

                // Sets people id in viewState
                ViewState["users"] = users;

                // Load the dropDownList
                DdlRegion.DataSource     = BRegions.getAll();
                DdlRegion.DataTextField  = "Name";
                DdlRegion.DataValueField = "RegionId";
                DdlRegion.DataBind();

                // Set the value of the record
                DdlRegion.SelectedValue = users.RegionId.ToString();
                boxName.Text            = users.Name;
                boxLastName.Text        = users.LastName;
                boxDNI.Text             = users.Dni.ToString();
                boxSignUp.Text          = users.SignUpDate.ToShortDateString();
                boxRenewal.Text         = users.RenewalDate.ToShortDateString();
                boxUserName.Text        = users.UserName;
                boxPass.Text            = users.Pass;

                // Disable fields
                disableFields();
            }
        }
Esempio n. 7
0
        protected void fillUsersGrid()
        {
            // Fill the grid and save it in viewState
            allUsers = BUsers.getAllUserDTO();
            ViewState["allUsers"] = allUsers;

            GridMainDetailsUser.DataSource = allUsers;
            GridMainDetailsUser.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Fill the grid
            List <UserDTO> allUsers = new List <UserDTO>();

            allUsers = BUsers.getAllUserDTO();

            GridDeleteListUser.DataSource = allUsers;
            GridDeleteListUser.DataBind();
        }
Esempio n. 9
0
        public ActionResult CreateOrEdit(UserModel model)
        {
            BUsers user = AutoMapper <UserModel, BUsers> .Map(model);

            var email = new System.Net.Mail.MailAddress(model.Email);

            if ((email.Address == model.Email) == true)
            {
                userService.CreateOrUpdate(user);
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 10
0
        public ActionResult Delete(int id)
        {
            BUsers user = AutoMapper <BUsers, BUsers> .Map(userService.GetUser, (int)id);

            user.IsDeleted = true;
            userService.CreateOrUpdate(user);
            if (Request.Cookies["authCookie"] != null)
            {
                Response.Cookies["authCookie"].Value = "";
            }
            return(RedirectToAction("Index", "Books"));
        }
Esempio n. 11
0
        public ActionResult Link(int id)
        {
            BUsers      user = userService.GetUser(id);
            MailAddress from = new MailAddress("*****@*****.**", "Reader's Club");
            MailAddress to   = new MailAddress(user.Email);
            MailMessage m    = new MailMessage(from, to);

            m.Subject    = "Просроченная книга";
            m.Body       = string.Format("<h2>Уважаемый" + user.Name + ", Вы просрочили срок сдачи книги! Вы заведены в список должников до того момента, пока не вернете книгу.</h2>");
            m.IsBodyHtml = true;
            SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mail.ru", 587);

            smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "засекречено");
            smtp.EnableSsl   = true;
            smtp.Send(m);
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        public void CreateOrUpdate(BUsers user)
        {
            if (user.Id == 0)
            {
                Users duser = new Users()
                {
                    Login = user.Login, Email = user.Email, IsDeleted = false, Password = user.Password, RoleId = user.RoleId
                };
                Database.Users.Create(duser);
            }
            else
            {
                Users editUser = AutoMapper <BUsers, Users> .Map(user);

                Database.Users.Update(editUser);
            }
            Database.Save();
        }
Esempio n. 13
0
        public void CreateOrUpdate(BUsers user)
        {
            if (user.Id == 0)
            {
                Users duser = new Users()
                {
                    Name = user.Name, Email = user.Email
                };
                Database.Users.Create(duser);
            }
            else
            {
                Users editUser = AutoMapper <BUsers, Users> .Map(user);

                Database.Users.Update(editUser);
            }
            Database.Save();
        }
Esempio n. 14
0
        protected void filterUsers()
        {
            // 1.- Get the last data source from viewstate
            allUsers = (List <UserDTO>)ViewState["allUsers"];

            // 2.- Filter by Region if value is not -1
            if (DropDownRegion.SelectedValue != "-1")
            {
                allUsers = BUsers.filterByRegion(allUsers, DropDownRegion.SelectedItem.Text);
            }

            // 3.- Filter by KeyWord
            allUsers = BUsers.filterByNameLastNameDni(allUsers, TextBoxSearch.Text);

            // 4.- Bind grid and save it in viewstate
            ViewState["filterUsers"]       = allUsers;
            GridMainDetailsUser.DataSource = allUsers;
            GridMainDetailsUser.DataBind();
        }
Esempio n. 15
0
        protected void ButtonDelete_Click(object sender, EventArgs e)
        {
            // Get the record
            users = (DataLibrary.Users)ViewState["users"];

            // Gets people and user index
            userIndex   = users.UserId;
            peopleIndex = users.PeopleId;

            try
            {
                // Delete Users
                BUsers.deleteById(userIndex, peopleIndex);
                Response.Redirect("~/Users/MainList.aspx");
            }
            catch (Exception generalException)
            {
                PanelDeleteUser.Visible = true;
                LiteralDeleteUser.Text  = generalException.Message;
            }
        }
        public ActionResult Link(int id)
        {
            BUsers      user = userService.GetUser(id);
            MailAddress from = new MailAddress("*****@*****.**", "RETURN MY BOOK!!!");
            // кому отправляем
            MailAddress to = new MailAddress(user.Email);
            // создаем объект сообщения
            MailMessage m = new MailMessage(from, to);

            // тема письма
            m.Subject = "RETURN MY BOOK!!!";
            // текст письма - включаем в него ссылку
            m.Body       = string.Format(user.Name + " верни книгу!!!!!");
            m.IsBodyHtml = true;
            // адрес smtp-сервера, с которого мы и будем отправлять письмо
            SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mail.ru", 587);

            // логин и пароль
            smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "sanyaug777888");
            smtp.EnableSsl   = true;
            smtp.Send(m);
            return(RedirectToAction("Index"));
        }
Esempio n. 17
0
        public BUsers GetUser(int id)
        {
            BUsers user = AutoMapper <Users, BUsers> .Map(Database.Users.Find(i => i.Id == id).FirstOrDefault());

            return(user);
        }
Esempio n. 18
0
 // PUT api/<controller>/5
 public void PutUser(int id, BUsers value)
 {
     userService.CreateOrUpdate(value);
 }
Esempio n. 19
0
 // POST api/<controller>
 public BUsers PostUser(BUsers value)
 {
     return(userService.CreateOrUpdate(value));
 }