예제 #1
0
        public ActionResult AddManager(Manager manager, HttpPostedFileBase file)
        {
            ManagerRepository managerrepo = new ManagerRepository();

            if (managerrepo.GetByName(manager.Username))
            {
                TempData["error"] = "Username already taken";
                return(View());
            }
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = System.IO.Path.Combine(Server.MapPath("~/content/image"), System.IO.Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    manager.ImageFIle = System.IO.Path.GetFileName(file.FileName);
                }
                catch (Exception exp)
                {
                    ViewBag.Message = "ERROR:" + exp.Message.ToString();
                    return(View());
                }
            }
            manager.Usertype = "manager";
            managerrepo.Insert(manager);
            TempData["success"] = "Registration done!";
            return(RedirectToAction("Index", "Login"));
        }
 public ActionResult updateInfo(Manager manager)
 {
     if (Session["existUser"].ToString() != manager.Username && managerRepository.GetByName(manager.Username))
     {
         TempData["error"] = "Username already taken";
         return(RedirectToAction("ManagerProfile"));
     }
     manager.Usertype = "manaer";
     managerRepository.Update(manager);
     return(RedirectToAction("ManagerProfile"));
 }
예제 #3
0
        public async Task <ViewResult <LoginModel> > Login(string userName, string userPwd)
        {
            var result     = new ViewResult <LoginModel>();
            var loginModel = new LoginModel();

            try
            {
                var customer = await _customerRepository.GetByName(userName);

                var manager = await _managerRepository.GetByName(userName);

                if (customer != null)
                {
                    if (customer.LoginPassword == userPwd)
                    {
                        loginModel.Id       = customer.Id;
                        loginModel.Logo     = customer.Logo;
                        loginModel.Name     = customer.LoginId;
                        loginModel.Role     = Constants.RoleCustomer;
                        loginModel.Customer = customer.ToCustomerModelForLogin();
                        result.Data         = loginModel;
                        return(result);
                    }
                    result.Status  = -3;
                    result.Message = "The username and password you entered did not match our record. Please double-check and try again.";
                    return(result);
                }
                if (manager != null)
                {
                    if (manager.Password == userPwd)
                    {
                        loginModel.Id   = manager.Id;
                        loginModel.Name = manager.LoginName;
                        loginModel.Role = manager.Role;
                        result.Data     = loginModel;

                        return(result);
                    }
                    result.Status  = -3;
                    result.Message = "The username and password you entered did not match our record. Please double-check and try again.";
                    return(result);
                }
                result.Status  = -2;
                result.Message = "The username and password you entered did not match our record. Please double-check and try again.";
            }
            catch (Exception ex)
            {
                result.Status  = -1;
                result.Message = ex.Message;
                Logger.WriteErrorLog("AccountService", "Login", ex);
            }
            return(result);
        }
예제 #4
0
        public Manager GetOrCreate(string name)
        {
            var managerRepo = new ManagerRepository();

            Manager manager = managerRepo.GetByName(name);



            if (manager == null)
            {
                manager = new Manager()
                {
                    ManagerName = name
                };

                managerRepo.Insert(manager);
            }

            return(manager);
        }