Exemplo n.º 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");
        }
Exemplo n.º 2
0
        public async Task <JsonResult> DeleteBranch(BranchModel model)
        {
            if (ModelState.IsValid)
            {
                var branch = new IdentityBranch(model.Id, model.BranchName, model.BranchCode);
                var result = await BranchManager.DeleteAsync(branch);

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