Пример #1
0
        public async Task <JsonResult> RegisterNewBranch(BranchModel model)
        {
            if (ModelState.IsValid)
            {
                var branchExist = BranchManager.BranchExists(model.BranchName);
                if (branchExist)
                {
                    throw new Exception("Branch already exist");
                }

                var branchCodeExist = BranchManager.BranchExists(model.BranchCode);
                if (branchCodeExist)
                {
                    throw new Exception("Branch Code already exist");
                }

                var branch = new IdentityBranch(model.BranchName, model.BranchCode);
                var result = await BranchManager.CreateAsync(branch);

                if (result)
                {
                    return(Json(new { code = "00", message = "Sucessfull" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    throw new Exception("Branch creation failed");
                }
            }
            throw new Exception("Invalid Data Submitted");
        }