コード例 #1
0
        public IActionResult ViewSellReport(int month, int year)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 5))
                {
                    if (month == 0 || year == 0)
                    {
                        ViewData["Message"] = BootstrapMessages.Failed("Please select month or year");

                        ViewBag.Years = orderManager.GetYearsForDropDown();
                        return(View());
                    }
                    else
                    {
                        return(RedirectToAction("Reporting", "OrderItem", new { month = month, year = year }));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
コード例 #2
0
        public IActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = authManager.LogIn(model);

                if (employee != null)
                {
                    var userData = JsonConvert.SerializeObject(employee);
                    HttpContext.Session.SetString("employee", userData);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    HttpContext.Session.SetString("employee", "");

                    ViewData["Message"] = BootstrapMessages.Failed("Invalid User Name or Password");
                    return(RedirectToAction("Login", "Auth"));
                }
            }
            else
            {
                HttpContext.Session.SetString("employee", "");

                ViewData["Message"] = BootstrapMessages.Failed("Fill up all fields correctly");
                return(RedirectToAction("Login", "Auth"));
            }
        }
コード例 #3
0
        public IActionResult ChangeProfilePicture(IFormFile profilePicture)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (profilePicture != null)
                {
                    string fileName = Guid.NewGuid() + "_" + profilePicture.FileName;

                    string uploaded = fileUpload.UploadEmployeeProfilePicture(profilePicture, fileName);

                    if (uploaded.Equals("1"))
                    {
                        Employee employeeModel = employeeManager.GetEmployeeById(employee.Id);

                        employeeModel.ProfilePicture = "http://www.ecom.somee.com/EmployeeProfile/" + fileName;
                        employeeModel.ActionBy       = employee.UserName;
                        employeeModel.ActionDone     = ActionAttributes.ActionUpdate;
                        employeeModel.ActionTime     = DateTime.Now.ToString("F");

                        string updated = employeeManager.Update(employeeModel);

                        if (updated.Equals("1"))
                        {
                            ViewData["ProfilePicture"] = employeeModel.ProfilePicture;
                            var userData = JsonConvert.SerializeObject(employeeModel);
                            HttpContext.Session.SetString("employee", userData);
                        }
                        else
                        {
                            ViewData["ProfilePicture"] = employee.ProfilePicture;
                            ViewData["Message"]        = updated;
                        }
                    }
                    else
                    {
                        ViewData["ProfilePicture"] = employee.ProfilePicture;
                        ViewData["Message"]        = BootstrapMessages.Failed(" Failed to Upload New Profile Picture");
                    }
                }
                else
                {
                    ViewData["ProfilePicture"] = employee.ProfilePicture;
                    ViewData["Message"]        = BootstrapMessages.Failed(" Browse one file");
                }

                return(View());
            }
        }
コード例 #4
0
        public IActionResult ChangePassword(ChangePasswordViewModel changePasswordViewModel)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (ModelState.IsValid)
                {
                    if (employee.Password.Equals(changePasswordViewModel.OldPassword))
                    {
                        if (changePasswordViewModel.NewPassword.Equals(changePasswordViewModel.ReEnterPassword))
                        {
                            Employee employeeModel = employeeManager.GetEmployeeById(employee.Id);

                            employeeModel.Password   = changePasswordViewModel.NewPassword;
                            employeeModel.ActionBy   = employee.UserName;
                            employeeModel.ActionDone = ActionAttributes.ActionUpdate;
                            employeeModel.ActionTime = DateTime.Now.ToString("F");

                            string updated = employeeManager.Update(employeeModel);

                            if (updated.Equals("1"))
                            {
                                return(RedirectToAction("Logout", "Auth"));
                            }
                            else
                            {
                                ViewData["Message"] = updated;
                            }
                        }
                        else
                        {
                            ViewData["Message"] = BootstrapMessages.Warning("New and Re Entered Password does not matched");
                        }
                    }
                    else
                    {
                        ViewData["Message"] = BootstrapMessages.Failed("Invalid Old Password");
                    }
                }
                else
                {
                    ViewData["Message"] = BootstrapMessages.Failed("Fill up all fields correctly");
                }

                return(View());
            }
        }
        public IActionResult Edit(Category category)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 1))
                {
                    if (categoryManager.IsExists(category.Id))
                    {
                        if (ModelState.IsValid)
                        {
                            category.ActionBy   = employee.UserName;
                            category.ActionName = ActionAttributes.ActionUpdate;
                            category.ActionTime = DateTime.Now.ToString("F");
                            category.State      = 1;

                            string updated = categoryManager.Update(category);

                            if (updated.Equals("1"))
                            {
                                return(RedirectToAction("ViewAll", "Category"));
                            }
                            else
                            {
                                Category categoryModel = categoryManager.GetCategoryById(category.Id);
                                ViewData["Message"] = updated;
                                return(View(categoryModel));
                            }
                        }
                        else
                        {
                            Category categoryModel = categoryManager.GetCategoryById(category.Id);
                            ViewData["Message"] = BootstrapMessages.Warning("Fill up all fields correctly");
                            return(View(categoryModel));
                        }
                    }
                    else
                    {
                        return(NotFound("404- Not Found"));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
コード例 #6
0
        public IActionResult UserAccess(UserAccess userAccess)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 4))
                {
                    if (ModelState.IsValid)
                    {
                        userAccess.Id         = 0;
                        userAccess.ActionBy   = employee.UserName;
                        userAccess.ActionTime = DateTime.Now.ToString("F");
                        userAccess.ActionDone = ActionAttributes.ActionInsert;
                        userAccess.State      = 1;

                        string saved = userAccessManager.SaveUserAccess(userAccess);
                        ViewData["userId"] = userAccess.UserId;

                        if (saved.Equals("1"))
                        {
                            return(RedirectToAction("UserAccess", "Employee", new { id = userAccess.UserId }));
                        }
                        else
                        {
                            ViewData["Message"] = saved;
                        }

                        ViewBag.UserAccesses = userAccessManager.GetAccessByUserId(userAccess.UserId);
                        ModelState.Clear();
                        return(View());
                    }
                    else
                    {
                        ViewData["Message"]  = BootstrapMessages.Failed("Fill up all fields correctly");
                        ViewData["userId"]   = userAccess.UserId;
                        ViewBag.UserAccesses = userAccessManager.GetAccessByUserId(userAccess.UserId);

                        return(View());
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        public IActionResult Edit(Designation designation)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 3))
                {
                    if (designationManager.IsExists(designation.Id))
                    {
                        if (ModelState.IsValid)
                        {
                            designation.ActionBy   = employee.UserName;
                            designation.ActionDone = ActionAttributes.ActionUpdate;
                            designation.ActionTime = DateTime.Now.ToString("F");
                            designation.State      = 1;

                            string updated = designationManager.Update(designation);

                            if (updated.Equals("1"))
                            {
                                return(RedirectToAction("ViewAll", "Designation"));
                            }
                            else
                            {
                                ViewData["Message"] = updated;
                                return(View(designation));
                            }
                        }
                        else
                        {
                            ViewData["Message"] = BootstrapMessages.Warning("Fill up all fields correctly");
                            Designation designationModel = designationManager.GetById(designation.Id);
                            return(View(designationModel));
                        }
                    }
                    else
                    {
                        return(NotFound("404- Not Found"));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        // update
        public string Update(Employee employee)
        {
            unitOfWork.Employee.Update(employee);
            int rowsAffected = unitOfWork.Completed();

            if (rowsAffected > 0)
            {
                return("1");
            }
            else
            {
                return(BootstrapMessages.Failed("Failed to Update Employee"));
            }
        }
コード例 #9
0
        public IActionResult Edit(Employee employee)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employeeData = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employeeData.Id, 4))
                {
                    if (ModelState.IsValid)
                    {
                        employee.ActionBy   = employeeData.UserName;
                        employee.ActionTime = DateTime.Now.ToString("F");
                        employee.ActionDone = ActionAttributes.ActionUpdate;
                        employee.State      = 1;

                        string updated = employeeManager.Update(employee);

                        if (updated.Equals("1"))
                        {
                            return(RedirectToAction("ViewEmployee", "Employee"));
                        }
                        else
                        {
                            ViewBag.Desigantions = designationManager.GetDesignationForDropDown();
                            ViewData["Message"]  = updated;

                            return(View(employee));
                        }
                    }
                    else
                    {
                        ViewBag.Desigantions = designationManager.GetDesignationForDropDown();
                        ViewData["Message"]  = BootstrapMessages.Failed("Fill up all fields correctly");

                        return(View(employee));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        // save employee
        public string Save(Employee employee)
        {
            if (unitOfWork.Employee.IsExists(x => x.UserName == employee.UserName && x.State == 1))
            {
                return(BootstrapMessages.Warning("Same UserName is already Exists"));
            }
            else
            {
                unitOfWork.Employee.Add(employee);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return(BootstrapMessages.Success("New Employee Saved Successfully"));
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to save new employee"));
                }
            }
        }
        // update
        public string Update(Category category)
        {
            if (unitOfWork.Category.IsExists(x => x.Name == category.Name && x.State == 1 && x.Id != category.Id))
            {
                return(BootstrapMessages.Warning("Category Already Exists"));
            }
            else
            {
                unitOfWork.Category.Update(category);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return("1");
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Update New Category"));
                }
            }
        }
        // save category
        public string Add(Category category)
        {
            if (unitOfWork.Category.IsExists(x => x.Name == category.Name && x.State == 1))
            {
                return(BootstrapMessages.Warning("Category Already Exists"));
            }
            else
            {
                unitOfWork.Category.Add(category);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return(BootstrapMessages.Success("Added New Category"));
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Add New Category"));
                }
            }
        }
        // save designation
        public string Save(Designation designation)
        {
            if (unitOfWork.Designation.IsExists(x => x.Name == designation.Name && x.State == 1))
            {
                return(BootstrapMessages.Warning("Designation already exists"));
            }
            else
            {
                unitOfWork.Designation.Add(designation);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return(BootstrapMessages.Success("New Designation Added Successfully"));
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Add New Designation"));
                }
            }
        }
コード例 #14
0
        // save delivery
        public string Save(Delivery delivery)
        {
            if (unitOfWork.Delivery.IsExists(x => x.PlaceName == delivery.PlaceName && x.State == 1))
            {
                return(BootstrapMessages.Failed("Place Name already exists"));
            }
            else
            {
                unitOfWork.Delivery.Add(delivery);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return(BootstrapMessages.Success("Delivery Info Successfully Saved"));
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Save delivery info"));
                }
            }
        }
        // save product
        public string Save(Product product)
        {
            if (unitOfWork.Product.IsExists(x => x.ProductTitle == product.ProductTitle && x.State == 1))
            {
                return(BootstrapMessages.Warning("Same Title Product Already Exists"));
            }
            else
            {
                unitOfWork.Product.Add(product);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return(BootstrapMessages.Success("Product Entry Successfully"));
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Entry New Product"));
                }
            }
        }
        // update
        public string Update(Product product)
        {
            if (unitOfWork.Product.IsExists(x =>
                                            x.ProductTitle == product.ProductTitle && x.State == 1 && x.Id != product.Id))
            {
                return(BootstrapMessages.Warning("Product Title already exists"));
            }
            else
            {
                unitOfWork.Product.Update(product);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return("1");
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Update Product"));
                }
            }
        }
        // update
        public string Update(Designation designation)
        {
            if (unitOfWork.Designation.IsExists(x =>
                                                x.Name == designation.Name && x.Id != designation.Id && x.State == 1))
            {
                return(BootstrapMessages.Warning("Designation Already Exists"));
            }
            else
            {
                unitOfWork.Designation.Update(designation);
                int updated = unitOfWork.Completed();

                if (updated > 0)
                {
                    return("1");
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to Update Designation"));
                }
            }
        }
コード例 #18
0
        //update
        public string Update(Delivery delivery)
        {
            if (unitOfWork.Delivery.IsExists(x =>
                                             x.PlaceName == delivery.PlaceName && x.State == 1 && x.Id != delivery.Id))
            {
                return(BootstrapMessages.Failed("Place Name already exists"));
            }
            else
            {
                unitOfWork.Delivery.Update(delivery);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return("1");
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to update delivery info"));
                }
            }
        }
        // save user access
        public string SaveUserAccess(UserAccess userAccess)
        {
            if (unitOfWork.UserAccess.IsExists(x =>
                                               x.UserId == userAccess.UserId && x.PageId == userAccess.PageId && x.State == 1))
            {
                return(BootstrapMessages.Failed("Access already given"));
            }
            else
            {
                unitOfWork.UserAccess.Add(userAccess);
                int rowsAffected = unitOfWork.Completed();

                if (rowsAffected > 0)
                {
                    return("1");
                }
                else
                {
                    return(BootstrapMessages.Failed("Failed to give access"));
                }
            }
        }
        public IActionResult Add(Designation designation)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 3))
                {
                    if (ModelState.IsValid)
                    {
                        designation.ActionBy   = employee.UserName;
                        designation.ActionDone = ActionAttributes.ActionInsert;
                        designation.ActionTime = DateTime.Now.ToString("F");
                        designation.State      = 1;

                        string saved = designationManager.Save(designation);
                        ViewData["Message"] = saved;
                        ModelState.Clear();
                        return(View());
                    }
                    else
                    {
                        ViewData["Message"] = BootstrapMessages.Warning("Fill up all fields correctly");
                        return(View(designation));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
コード例 #21
0
        public IActionResult Add(Employee employee, IFormFile picture)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employeeData = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employeeData.Id, 4))
                {
                    if (ModelState.IsValid)
                    {
                        employee.Password   = "******";
                        employee.ActionBy   = employeeData.UserName;
                        employee.ActionDone = ActionAttributes.ActionInsert;
                        employee.ActionTime = DateTime.Now.ToString("F");
                        employee.State      = 1;

                        if (picture == null)
                        {
                            employee.ProfilePicture = "http://www.ecom.somee.com/EmployeeProfile/avater.jpg";
                        }
                        else
                        {
                            string fileName = Guid.NewGuid().ToString() + "_" + picture.FileName;
                            string response = fileUpload.UploadEmployeeProfilePicture(picture, fileName);

                            if (response.Equals("1"))
                            {
                                employee.ProfilePicture    = "http://www.ecom.somee.com/EmployeeProfile/" + fileName;
                                ViewData["PictureMessage"] =
                                    BootstrapMessages.Success("Picture Uploaded Successfully.");
                            }
                            else
                            {
                                employee.ProfilePicture    = "http://www.ecom.somee.com/EmployeeProfile/avater.jpg";
                                ViewData["PictureMessage"] =
                                    BootstrapMessages.Failed("Picture Uploaded Failed. Reason: " + response);
                            }
                        }

                        string saved = employeeManager.Save(employee);
                        ViewData["Message"] = saved;

                        ViewBag.Desigantions = designationManager.GetDesignationForDropDown();
                        ModelState.Clear();
                        return(View());
                    }
                    else
                    {
                        ViewData["Message"]  = BootstrapMessages.Warning("Fill up all fields correctly");
                        ViewBag.Desigantions = designationManager.GetDesignationForDropDown();
                        return(View());
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        public IActionResult Add(Product product, IFormFile picture)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 6))
                {
                    if (picture != null)
                    {
                        if (ModelState.IsValid)
                        {
                            DateTime entryDate = DateTime.Parse(product.EntryDate);

                            product.EntryMonth = entryDate.Month;
                            product.EntryYear  = entryDate.Year;

                            product.Profit = product.SellPrice - product.BasePrice;

                            product.ActionBy   = employee.UserName;
                            product.ActionDone = ActionAttributes.ActionInsert;
                            product.ActionTime = DateTime.Now.ToString("F");

                            string fileName = Guid.NewGuid().ToString() + "_" + picture.FileName;
                            product.PictureUrl = "http://www.ecom.somee.com/Pictures/" + fileName;
                            product.State      = 1;

                            string uploadPictureMessage = ftpFileUpload.UploadProductPicture(picture, fileName);

                            if (uploadPictureMessage.Equals("1"))
                            {
                                ViewData["Message"] = productManager.Save(product);
                                ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                                ModelState.Clear();
                                return(View());
                            }
                            else
                            {
                                ViewData["Message"] = BootstrapMessages.Failed("Data Not Saved for failure of Picture Upload. Reason: " + uploadPictureMessage);
                                ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                                ModelState.Clear();
                                return(View());
                            }
                        }
                        else
                        {
                            ViewData["Message"] = BootstrapMessages.Warning("Fill up all fields correctly");
                            ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                            return(View());
                        }
                    }
                    else
                    {
                        ViewData["Message"] = BootstrapMessages.Failed("Must Browse Product Picture");
                        ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                        return(View());
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        public IActionResult Edit(Product product, IFormFile picture)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 6))
                {
                    if (productManager.IsProductExists(product.Id))
                    {
                        if (ModelState.IsValid)
                        {
                            DateTime entryDate = DateTime.Parse(product.EntryDate);

                            product.EntryMonth = entryDate.Month;
                            product.EntryYear  = entryDate.Year;

                            product.Profit = product.SellPrice - product.BasePrice;

                            product.ActionBy   = employee.UserName;
                            product.ActionDone = ActionAttributes.ActionUpdate;
                            product.ActionTime = DateTime.Now.ToString("F");

                            product.State = 1;

                            if (picture != null)
                            {
                                string fileName = Guid.NewGuid().ToString() + "_" + picture.FileName;
                                product.PictureUrl = " http://www.ecom.somee.com/Pictures/" + fileName;

                                ftpFileUpload.UploadProductPicture(picture, fileName);

                                string updated = productManager.Update(product);

                                if (updated.Equals("1"))
                                {
                                    return(RedirectToAction("ViewAll", "Product"));
                                }
                                else
                                {
                                    Product productBack = productManager.GetById(product.Id);
                                    ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                                    ViewData["Message"] = updated;

                                    return(View(productBack));
                                }
                            }
                            else
                            {
                                string updated = productManager.Update(product);

                                if (updated.Equals("1"))
                                {
                                    return(RedirectToAction("ViewAll", "Product"));
                                }
                                else
                                {
                                    Product productBack = productManager.GetById(product.Id);
                                    ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                                    ViewData["Message"] = updated;

                                    return(View(productBack));
                                }
                            }
                        }
                        else
                        {
                            Product productBack = productManager.GetById(product.Id);
                            ViewBag.Categories  = categoryManager.GetCategoriesForDropDown();
                            ViewData["Message"] = BootstrapMessages.Warning("Fill up all fields correctly");

                            return(View(productBack));
                        }
                    }
                    else
                    {
                        return(NotFound("404- Not Found"));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        public IActionResult RegisterUser(UserViewModel user)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 7))
                {
                    if (ModelState.IsValid)
                    {
                        User userModel = new User();
                        userModel.UserName            = user.UserName;
                        userModel.Email               = user.Email;
                        userModel.Password            = "******";
                        userModel.Phone               = user.Phone;
                        userModel.VerificationCode    = random.Next(1000, Int32.MaxValue).ToString();
                        userModel.Verify              = 0;
                        userModel.AccountCreatingTime = DateTime.Now.ToString("F");
                        userModel.State               = 1;

                        string saved = userManager.RegisterUser(userModel);

                        if (saved.Equals("1"))
                        {
                            string subject = "BD Market. Account Registration Verification";
                            string body    = "<p>Dear " + user.UserName +
                                             "</p><p>Thank you for choosing our e-commerce site for shopping. To Open or Register New Account, you have to verify your account email address. Your verification code is <strong>" +
                                             userModel.VerificationCode + "</strong>.</p><p>Thank You. Happy Shopping.</p>";

                            MailMessage mail = new MailMessage();
                            mail.To.Add(user.Email);
                            mail.From       = new MailAddress("*****@*****.**");
                            mail.Subject    = subject;
                            mail.Body       = body;
                            mail.IsBodyHtml = true;

                            SmtpClient smtp = new SmtpClient();
                            smtp.Host = "smtp.gmail.com";
                            smtp.Port = 587;
                            smtp.UseDefaultCredentials = true;
                            smtp.Credentials           = new System.Net.NetworkCredential
                                                             ("*****@*****.**", "password");
                            smtp.EnableSsl = true;
                            smtp.Send(mail);

                            ViewData["Message"] = BootstrapMessages.Success("Register Successful");
                        }
                        else if (saved.Equals("2"))
                        {
                            ViewData["Message"] = BootstrapMessages.Success("User Email already exists");
                        }
                        else
                        {
                            ViewData["Message"] = BootstrapMessages.Success("Failed to Register New User");
                        }

                        ModelState.Clear();
                        return(View());
                    }
                    else
                    {
                        ViewData["Message"] = BootstrapMessages.Failed("Fill up all fields correctly");
                        return(View());
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }
        public IActionResult StockIn(int quantity, int productId)
        {
            var employeeDataString = HttpContext.Session.GetString("employee");

            if (employeeDataString == "")
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                Employee employee = JsonConvert.DeserializeObject <Employee>(employeeDataString);

                if (userAccessManager.IsAccessExists(employee.Id, 6))
                {
                    if (productManager.IsProductExists(productId))
                    {
                        if (quantity > 1 || quantity < 10000000)
                        {
                            Product item = productManager.GetById(productId);

                            item.ActionBy   = employee.UserName;
                            item.ActionDone = ActionAttributes.ActionUpdate;
                            item.ActionTime = DateTime.Now.ToString("F");
                            item.State      = 1;

                            item.Quantity = item.Quantity + quantity;

                            string updated = productManager.Update(item);

                            if (updated.Equals("1"))
                            {
                                return(RedirectToAction("ViewAll", "Product"));
                            }
                            else
                            {
                                Product itemData = productManager.GetById(productId);

                                ViewData["ProductId"]    = itemData.Id;
                                ViewData["ProductTitle"] = itemData.ProductTitle;
                                ViewData["PrevQuantity"] = itemData.Quantity;
                                ViewData["Message"]      = updated;

                                return(View());
                            }
                        }
                        else
                        {
                            Product item = productManager.GetById(productId);

                            ViewData["ProductId"]    = item.Id;
                            ViewData["ProductTitle"] = item.ProductTitle;
                            ViewData["PrevQuantity"] = item.Quantity;
                            ViewData["Message"]      = BootstrapMessages.Warning("Fill up all fields correctly");

                            return(View());
                        }
                    }
                    else
                    {
                        return(NotFound("404- Not Found"));
                    }
                }
                else
                {
                    return(NotFound("No Access"));
                }
            }
        }