Пример #1
0
 public Branch Add(Branch branch)
 {
     using (SqlConnection conn = _manager.GetConnection())
     {
         SqlTransaction t = conn.BeginTransaction();
         try
         {
             ValidateBranch(branch);
             LoadBranches();
             _manager.Add(branch, t);
             _branches.Add(branch);
             if (t != null)
             {
                 t.Commit();
             }
             return(branch);
         }
         catch (Exception e)
         {
             if (t != null)
             {
                 t.Rollback();
             }
             throw e;
         }
     }
 }
        public ActionResult Save(BranchViewModel branchVm)
        {
            var branchVm2 = new BranchViewModel();

            branchVm2.Organizations = _organizationManager.GetAll();


            ModelState.Remove("Id");
            if (ModelState.IsValid)
            {
                if (branchVm.Id == 0)
                {
                    bool isShortNameExist = _branchManager.IsBranchShortNameExist(branchVm.ShortName, branchVm.OrganizationId);
                    if (isShortNameExist)
                    {
                        ViewBag.Message = "This Organization Short Name already Exist";

                        return(View("BranchForm", branchVm2));
                    }

                    var branch = new Branch()
                    {
                        OrganizationId = branchVm.OrganizationId,
                        Name           = branchVm.Name,
                        ShortName      = branchVm.ShortName,
                        BranchCode     = branchVm.BranchCode
                    };
                    _branchManager.Add(branch);

                    ModelState.Clear();
                    return(View("BranchForm", branchVm2));
                }

                var branchInDb = _branchManager.SingleBranch(branchVm.Id);
                if (branchInDb == null)
                {
                    return(HttpNotFound());
                }

                branchInDb.OrganizationId = branchVm.OrganizationId;
                branchInDb.Name           = branchVm.Name;
                branchInDb.ShortName      = branchVm.ShortName;
                branchInDb.BranchCode     = branchVm.BranchCode;
                _branchManager.Update(branchInDb);
                ModelState.Clear();
                return(View("BranchList"));
            }

            return(View("BranchForm", branchVm2));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "Id,OrganizationId,Name,ShortName,BranchCode")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                bool isBranchName      = _branchManager.IsBranchNameExist(branch.Name);
                bool isBranchShortName = _branchManager.IsBranchShortNameExist(branch.ShortName);
                bool isBranchCode      = _branchManager.IsBranchCodeExist(branch.BranchCode);
                if (isBranchName)
                {
                    ViewBag.NameCssClass    = "Alert Alert-warning";
                    ViewBag.NameMessageType = "Warning";
                    ViewBag.NameMessage     = "This branch name is already exist!";
                }
                else if (isBranchShortName)
                {
                    ViewBag.ShortNameCssClass    = "Alert Alert-warning";
                    ViewBag.ShortNameMessageType = "Warning";
                    ViewBag.ShortNameMessage     = "This branch short-name is already exist!";
                }
                else if (isBranchCode)
                {
                    ViewBag.CodeCssClass    = "Alert Alert-warning";
                    ViewBag.CodeMessageType = "Warning";
                    ViewBag.CodeMessage     = "This branch code is already exist!";
                }
                else
                {
                    _branchManager.Add(branch);
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.OrganizationId = new SelectList(_organizationManager.GetAll(), "Id", "Name", branch.OrganizationId);

            return(View(branch));
        }
Пример #4
0
 public async Task <AddBranchOutput> AddBranch(Branch Branch)
 {
     return(await BranchManager.Add(Branch));
 }