Example #1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
                {
                    var user = dc.Users.Where(a => a.ResetCode == model.ResetPassCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.UserPassword = EncryptPassword.Hash(model.NewPassword);
                        user.ResetCode    = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "Employee_ID,User_ID,Employee_Name,Employee_Surname,Employee_Address,Emp_Phone,Emp_Email,ID_Number,EmpTitle_ID,EmpGender_ID,ImageData")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                /*string fileName = Path.GetFileNameWithoutExtension(employee.ImageFile.FileName);
                 * string extension = Path.GetExtension(employee.ImageFile.FileName);
                 * fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                 * employee.ImageData = "~/Image/" + fileName;
                 * fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
                 * employee.ImageFile.SaveAs(fileName);*/


                using (The_Book_MarketEntities db = new The_Book_MarketEntities())
                {
                    db.Employees.Add(employee);
                    db.SaveChanges();
                }
                ViewBag.FileStatus = "Employee Added successfully.";


                return(RedirectToAction("Index"));
            }
            ViewBag.EmpGender_ID = new SelectList(db.Employee_Gender, "EmpGender_ID", "Gender_Description", employee.EmpGender_ID);
            ViewBag.EmpTitle_ID  = new SelectList(db.Employee_Title, "EmpTitle_ID", "Title_Description", employee.EmpTitle_ID);
            ViewBag.User_ID      = new SelectList(db.Users, "User_ID", "UserName", employee.User_ID);
            return(View(employee));
        }
Example #3
0
        public ActionResult ResetPassword(string id)
        {
            //Verify the reset password link
            //Find account associated with this link
            //redirect to reset password page
            if (string.IsNullOrWhiteSpace(id))
            {
                return(HttpNotFound("Invalid user"));
            }

            using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
            {
                var user = dc.Users.Where(a => a.ResetCode == id).FirstOrDefault();
                if (user != null)
                {
                    ResetPasswordModel model = new ResetPasswordModel();
                    model.ResetPassCode = id;
                    return(View(model));
                }
                else
                {
                    return(HttpNotFound("Invalid user"));
                }
            }
        }
Example #4
0
        public ActionResult Login(UserLogin login, string ReturnUrl = "")
        {
            string message = "";

            using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
            {
                try
                {
                    var v = dc.Users.Where(a => a.UserName == login.UserName).FirstOrDefault();
                    if (v != null)
                    {
                        if (v.IsUserVerified == false)
                        {
                            ViewBag.Message = "Please verify your email first";
                            return(View());
                        }

                        if (string.Compare(EncryptPassword.Hash(login.UserPassword), v.UserPassword) == 0)
                        {
                            int    timeout   = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
                            var    ticket    = new FormsAuthenticationTicket(login.UserName, login.RememberMe, timeout);
                            string encrypted = FormsAuthentication.Encrypt(ticket);
                            var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                            cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                            cookie.HttpOnly = true;
                            Response.Cookies.Add(cookie);


                            if (Url.IsLocalUrl(ReturnUrl))
                            {
                                return(Redirect(ReturnUrl));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            message = "Invalid credential provided";
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                catch (Exception e)
                {
                    ViewBag.Message = e.Message;
                }
            }
            if (message != "")
            {
                ViewBag.Message = message;
            }

            return(View());
        }
Example #5
0
 public bool IsUserExist(string username)
 {
     using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
     {
         var v = dc.Users.Where(a => a.UserName == username).FirstOrDefault();
         return(v != null);
     }
 }
 public ActionResult GetData()
 {
     using (The_Book_MarketEntities db = new The_Book_MarketEntities())
     {
         List <Customer> customerList = db.Customers.ToList <Customer>();
         return(Json(new { data = customerList }, JsonRequestBehavior.AllowGet));
     }
 }
Example #7
0
        public ActionResult Register([Bind(Exclude = "IsUserVerified, GUID")] User user)
        {
            bool   Status  = false;
            string message = "";

            //
            // Model Validation
            if (ModelState.IsValid)
            {
                user.IsUserVerified = false;
                #region //User already Exist

                var isExist = IsUserExist(user.UserName);
                if (isExist)
                {
                    ModelState.AddModelError("UserExist", "User already exist");
                    return(View(user));
                }

                #endregion

                #region Generate user Activation Code
                user.GUID = Guid.NewGuid();
                #endregion

                #region  Password Hashing
                user.UserPassword = EncryptPassword.Hash(user.UserPassword);
                //user.PassConfirm = EncryptPassword.Hash(user.PassConfirm);
                #endregion

                #region Save user to Database

                using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

                    //Send Email to User
                    SendVerificationLinkEmail(user.UserName, user.GUID.ToString());
                    message = "Registration successfully done. Account activation link " +
                              " has been sent to user email id:" + user.UserName;
                    Status = true;
                }

                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message     = message;
            ViewBag.Status      = Status;
            ViewBag.UserRole_ID = new SelectList(db.User_Role, "UserRole_ID", "UserRole_Description", user.UserRole_ID);
            return(View(user));
        }
        public ActionResult Index(HttpPostedFileBase xmlFile)
        {
            if (xmlFile.ContentType.Equals("application/xml") || xmlFile.ContentType.Equals("text/xml"))
            {
                try
                {
                    var xmlPath = Server.MapPath("~/FileUpload" + xmlFile.FileName);
                    xmlFile.SaveAs(xmlPath);
                    XDocument       xDoc     = XDocument.Load(xmlPath);
                    List <Customer> custList = xDoc.Descendants("customer").Select
                                                   (customer => new Customer
                    {
                        Customer_ID      = Convert.ToInt32(customer.Element("id").Value),
                        Customer_Name    = customer.Element("name").Value,
                        Customer_Surname = customer.Element("surname").Value,
                        Customer_Email   = customer.Element("email").Value,
                        Customer_Contact = customer.Element("contact").Value
                    }).ToList();

                    using (The_Book_MarketEntities db = new The_Book_MarketEntities())
                    {
                        foreach (var i in custList)
                        {
                            var v = db.Customers.Where(a => a.Customer_ID.Equals(i.Customer_ID)).FirstOrDefault();

                            if (v != null)
                            {
                                v.Customer_ID      = i.Customer_ID;
                                v.Customer_Name    = i.Customer_Name;
                                v.Customer_Surname = i.Customer_Surname;
                                v.Customer_Email   = i.Customer_Email;
                                v.Customer_Contact = i.Customer_Contact;
                            }
                            else
                            {
                                db.Customers.Add(i);
                            }
                        }
                        db.SaveChanges();
                        ViewBag.Result = db.Customers.ToList();
                    }
                    return(View("Success"));
                }
                catch
                {
                    ViewBag.Error = "Cant Import XML File";
                    return(View("Index"));
                }
            }
            else
            {
                ViewBag.Error = "Cant Import XML File";
                return(View("Index"));
            }
        }
Example #9
0
        public ActionResult ForgotPassword(string userName)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
            {
                var account = dc.Users.Where(a => a.UserName == userName).FirstOrDefault();

                try
                {
                    if (account != null)
                    {
                        //Send email for reset password
                        string resetCode = Guid.NewGuid().ToString();
                        SendResetPasswordLinkEmail(account.UserName, resetCode);
                        //SendVerificationLinkEmail(account.UserName, resetCode);
                        account.ResetCode = resetCode;
                        // added to avoid confirm password area in model
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "Reset password link has been sent to your email id.";
                    }


                    else
                    {
                        message = "Account not found";
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string Message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
            ViewBag.Message = message;
            return(View());
        }
        public JsonResult GetInventory(string word, int page, int rows, string searchString, string sord)
        {
            using (The_Book_MarketEntities db = new The_Book_MarketEntities())
            {
                //#2 Setting Paging
                int pageIndex = Convert.ToInt32(page) - 1;
                int pageSize  = rows;

                //#3 Linq Query to Get Customer
                var Results = db.Inventories.Select(
                    a => new
                {
                    a.Inventory_ID,
                    a.InventoryType_ID,
                    a.Inventory_Name,
                    a.Inventory_Description,
                    a.Inventory_Quantity,
                    a.Minimum_Quantity,
                    a.StockTurn_ID,
                });

                //#4 Get Total Row Count
                int totalRecords = Results.Count();
                var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)rows);

                //#5 Setting Sorting
                if (sord.ToUpper() == "DESC")
                {
                    Results = Results.OrderByDescending(s => s.Inventory_ID);
                    Results = Results.Skip(pageIndex * pageSize).Take(pageSize);
                }
                else
                {
                    Results = Results.OrderBy(s => s.Inventory_ID);
                    Results = Results.Skip(pageIndex * pageSize).Take(pageSize);
                }
                //#6 Setting Search
                if (!string.IsNullOrEmpty(searchString))
                {
                    Results = Results.Where(m => m.Inventory_Description == searchString);
                }
                //#7 Sending Json Object to View.
                var jsonData = new
                {
                    total = totalPages,
                    page,
                    records = totalRecords,
                    rows    = Results
                };
                return(Json(jsonData, JsonRequestBehavior.AllowGet));
            }
        }
Example #11
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (The_Book_MarketEntities dc = new The_Book_MarketEntities())
            {
                /*dc.Configuration.ValidateOnSaveEnabled = false;
                 * // to avoid
                 * // Confirm password does not match issue on save changes*/
                var v = dc.Users.Where(a => a.GUID == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsUserVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }