public ActionResult Create(Branch branch)
        {
            int orgid = OwnerOrgId();

            if (orgid == 0)
            {
                ViewBag.orglist = organizationManager.GetAll();
            }
            else
            {
                var list = organizationManager.GetAll().Where(c => c.Id == orgid);
                ViewBag.orglist = list.ToList();

                var blist = branchManager.GetSome(5).Where(c => c.OrganizationId == orgid).ToList();
                if (blist.Count != 0)
                {
                    ViewBag.brlist = blist.ToList();
                }
            }

            if (branchManager.IsExist(branch.ShortName, branch.OrganizationId))
            {
                ViewData["exist"] = "This Short Name Already Exist";
            }
            else
            {
                branchManager.Add(branch);
                ModelState.Clear();
                return(RedirectToAction("Create", new { success = "true" }));
            }
            return(View(branch));
        }
Beispiel #2
0
        public ActionResult AddBranch(Branch model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool result = _iBranchManager.Add(model);
                    TempData["message"] = result;
                    ModelState.Clear();
                }

                return(View());
            }
            catch (Exception e)
            {
                ViewBag.Error = e?.Message;
                return(View());
            }
        }
        public IActionResult Create(Branch aBranch)
        {
            if (ModelState.IsValid)
            {
                bool isAdd = _iBranchManager.Add(aBranch);

                if (isAdd)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(ViewBag.ErrorMessage = "Branch has been not save!");
                }
            }

            ViewBag.CountryList = CountryList();
            return(View(aBranch));
        }
        public ActionResult Create([Bind(Include = "Id,Name,ShortName,Code,Description,BranchCode,OrganizationId,Organization.ShortName")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                ViewBag.OrganizationId = new SelectList(_branchManager.GetOrganizationCategories(), "Id", "Name");
                try
                {
                    branch.BranchCode = GetOrganizationShortName(branch);
                    _branchManager.Add(branch);
                } catch (Exception ex)
                {
                    ModelState.AddModelError("ShortName", ex.Message);
                    return(View());
                }

                return(RedirectToAction("Index"));
            }


            return(View(branch));
        }
Beispiel #5
0
        public ActionResult Create(Branch branch)
        {
            ViewBag.OrganizationList = GetOrganizations();

            if (ModelState.IsValid && branch != null)
            {
                ModelState.Clear();
                try
                {
                    var BranchList = _branchManager.GetAll(c => true);

                    int BranchExist = BranchList
                                      .Where(c => c.OrganizationId == branch.OrganizationId)
                                      .Where(c => c.ShortName == branch.ShortName)
                                      .Count();

                    if (BranchExist > 0)
                    {
                        branch.ShortName = null;
                        ModelState.AddModelError("ShortName",
                                                 "Short name for the branch already exists for the organization");
                    }
                    else
                    {
                        if (_branchManager.Add(branch))
                        {
                            ViewBag.Msg = "Branch added successfully!";
                            return(View());
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            return(View(branch));
        }