示例#1
0
        public ActionResult SaveUserBranch(int UserID, List <Branch> Check)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("UserBranch_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }
                    var IsExistBr = _userbranchService.All().Where(x => x.Userid == UserID.ToString()).ToList();
                    foreach (var data in IsExistBr)
                    {
                        _userbranchService.Delete(data);
                        _userbranchService.Save();
                    }
                    if (Check != null)
                    {
                        foreach (var data in Check)
                        {
                            if (Check.Count != 0)
                            {
                                List <UserBranch> userbranchList = new List <UserBranch>();

                                UserBranch userBranchAdd = new UserBranch();
                                userBranchAdd.BranchCode = data.BranchCode;
                                userBranchAdd.Userid     = UserID.ToString();

                                userbranchList.Add(userBranchAdd);

                                _userbranchService.Add(userBranchAdd);
                                _userbranchService.Save();
                            }

                            //else
                            //{
                            //
                            //}
                        }
                        // transaction.Dispose();
                        // return Json("3", JsonRequestBehavior.AllowGet);
                    }
                    transaction.Complete();
                    //Check.Clear();
                    return(Json("1", JsonRequestBehavior.AllowGet));
                }
                catch (Exception)
                {
                    transaction.Dispose();
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }
示例#2
0
 public void Delete(UserBranch obj)
 {
     _service.Delete(obj);
 }