Exemple #1
0
        public ActionResult Update(int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            IStaffService _staSrv = IoC.Resolve <IStaffService>();
            var           model   = _staSrv.Getbykey(id);

            try
            {
                TryUpdateModel <Staff>(model);
                _staSrv.Save(model);
                _staSrv.CommitChanges();
                log.Info("Edit staff by: " + HttpContext.User.Identity.Name + " Info-- TenNhanVien: " + model.FullName + " TaiKhoanNhanVien: " + model.AccountName + " Email: " + model.Email);
                Messages.AddFlashMessage(Resources.Message.Staff_UMesSuccess);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                log.Error("Edit-" + ex);
                Messages.AddErrorMessage(Resources.Message.Staff_UMesUnsuccess);
                return(View("Edit", model));
            }
        }
Exemple #2
0
 public ActionResult Edit(Staff model)
 {
     try
     {
         TryUpdateModel <Staff>(model);
         IStaffService service = IoC.Resolve <IStaffService>();
         service.Update(model);
         service.CommitChanges();
         return(RedirectToAction("StaffIndex"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #3
0
 public ActionResult Create(Staff staff)
 {
     try
     {
         TryUpdateModel <Staff>(staff);
         IStaffService service = IoC.Resolve <IStaffService>();
         service.CreateNew(staff);
         service.CommitChanges();
         return(RedirectToAction("StaffIndex"));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
Exemple #4
0
        public ActionResult Delete(int id)
        {
            IStaffService service = IoC.Resolve <IStaffService>();

            try
            {
                if (id < 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                var staff = service.Getbykey(id);
                if (staff == null)
                {
                    return(HttpNotFound());
                }
                service.Delete(staff);
                service.CommitChanges();
                return(RedirectToAction("StaffIndex"));
            }
            catch (Exception ex)
            {
                return(View("Error"));
            }
        }
        public ActionResult New(user temp, string RetypePassword, string[] UserRoles, string fullname)
        {
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            IRBACRoleProvider       _RoleProvider       = IoC.Resolve <IRBACRoleProvider>();

            if (string.IsNullOrWhiteSpace(temp.username))
            {
                AccountModel model = new AccountModel();
                Messages.AddErrorMessage("Cần nhập những thông tin bắt buộc.");
                List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                if (lst.IndexOf("ServiceRole") >= 0)
                {
                    lst.RemoveAt(lst.IndexOf("ServiceRole"));
                }
                if (lst.IndexOf("Root") >= 0)
                {
                    lst.RemoveAt(lst.IndexOf("Root"));
                }
                model.RetypePassword = temp.password = "";
                model.AllRoles       = lst.ToArray();
                model.UserRoles      = UserRoles ?? new string[] { };
                model.UserTmp        = temp;
                return(View("Create", model));
            }
            try
            {
                if (temp.password != RetypePassword)
                {
                    AccountModel model = new AccountModel();
                    Messages.AddErrorMessage(Resources.Message.User_MesConfirmPass);
                    List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                    if (lst.IndexOf("ServiceRole") >= 0)
                    {
                        lst.RemoveAt(lst.IndexOf("ServiceRole"));
                    }
                    if (lst.IndexOf("Root") >= 0)
                    {
                        lst.RemoveAt(lst.IndexOf("Root"));
                    }
                    model.RetypePassword = temp.password = "";
                    model.AllRoles       = lst.ToArray();
                    model.UserRoles      = UserRoles ?? new string[] { };
                    model.UserTmp        = temp;
                    return(View("Create", model));
                }
                //Tao tai khoan
                string  status     = "";
                Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                user    u          = _MemberShipProvider.CreateUser(temp.username, temp.password, temp.email, null, null, temp.IsApproved, null, currentCom.id.ToString(), out status);
                if (status != "Success")
                {
                    AccountModel model = new AccountModel();
                    Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ.");
                    List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                    if (lst.IndexOf("ServiceRole") >= 0)
                    {
                        lst.RemoveAt(lst.IndexOf("ServiceRole"));
                    }
                    if (lst.IndexOf("Root") >= 0)
                    {
                        lst.RemoveAt(lst.IndexOf("Root"));
                    }
                    model.RetypePassword = temp.password = "";
                    model.AllRoles       = lst.ToArray();
                    model.UserRoles      = UserRoles ?? new string[] { };
                    model.UserTmp        = temp;
                    return(View("Create", model));
                }
                _RoleProvider.UpdateUsersToRoles(u.userid, UserRoles);
                Messages.AddFlashMessage(Resources.Message.User_UMesSuccess);
                log.Info("Create Account:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now);

                Company       currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                IStaffService _staSrv     = IoC.Resolve <IStaffService>();
                Staff         newStaff    = new Staff
                {
                    FullName    = fullname,
                    AccountName = u.username,
                    ComID       = currentComp.id,
                    Email       = u.email
                };

                _staSrv.CreateNew(newStaff);
                _staSrv.CommitChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                log.Error("Create Error:", ex);
                AccountModel model = new AccountModel();
                Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ.");
                List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                if (lst.IndexOf("ServiceRole") >= 0)
                {
                    lst.RemoveAt(lst.IndexOf("ServiceRole"));
                }
                if (lst.IndexOf("Root") >= 0)
                {
                    lst.RemoveAt(lst.IndexOf("Root"));
                }
                model.RetypePassword = temp.password = "";
                model.AllRoles       = lst.ToArray();
                model.UserRoles      = new string[] { };
                model.UserTmp        = temp;
                return(View("Create", model));
            }
        }