public ActionResult Create(CreateDebtViewModel model)
        {
            ViewBag.Parent = "Quản lý giao hàng";
            ViewBag.Child  = "Thanh Toán Công nợ";
            isAdminLogged();
            var   user  = Session["admin"] as Account;
            Staff staff = _staffService.GetByAccount(user.UserName);
            var   debt  = new Debt
            {
                CreatedDate   = DateTime.Now,
                Purchase      = model.moneyDebt,
                idDistributor = model.idDistributor,
                idStaff       = staff.idStaff,
            };
            var result = _debtService.CreateDebt(debt);

            if (result == "thanh cong")
            {
                var dis = _distributorService.GetDistributor(model.idDistributor);
                dis.debt -= model.moneyDebt;
                _distributorService.UpdateDebt(dis.idDistributor, dis.debt.Value);
                model.debt    = dis.debt.Value;
                model.idDebt  = debt.idDebt;
                ViewBag.types = 2;
                ViewBag.msg   = "Lập phiếu công nợ thành công";
                return(RedirectToAction("Create", new { idDistributor = model.idDistributor }));
            }
            else
            {
                ViewBag.types = 1;
                ViewBag.msg   = "Lập phiếu công nợ thất bại";
                return(View(model));
            }
        }
Exemplo n.º 2
0
        public IActionResult Post([FromBody] DebtDtoRequest request)
        {
            try
            {
                var validRes = new NewDebtValidation().Validate(request);
                if (!validRes.IsValid)
                {
                    return(BadRequest(validRes.Errors));
                }

                var id = _debtService.CreateDebt(request);
                return(Created($"Game: {id}", null));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }