Exemple #1
0
        public DbResponse EditCost(ExpenseAddModel model)
        {
            try
            {
                var updateData = _db.Expenses.Edit(model);

                if (updateData == null)
                {
                    return(new DbResponse(false, "No data found"));
                }

                if (updateData.IsApproved)
                {
                    if (updateData.PrevAccountId != null)
                    {
                        _db.Account.BalanceAdd(updateData.PrevAccountId.Value, updateData.PrevAmount);
                    }

                    _db.SaveChanges();

                    if (updateData.CurrentAccountId != null)
                    {
                        _db.Account.BalanceSubtract(updateData.CurrentAccountId.Value, updateData.CurrentAmount);
                    }
                }

                _db.SaveChanges();

                return(new DbResponse(true, "Changed Successfully"));
            }
            catch (Exception e)
            {
                return(new DbResponse(false, e.Message));
            }
        }
Exemple #2
0
        public IActionResult UpdateGeneralExpense(ExpenseAddModel model)
        {
            ViewBag.ExpenseCategoryId = new SelectList(_db.ExpenseCategories.ddl(), "value", "label");

            var response = _expense.EditCost(model);

            if (response.IsSuccess)
            {
                return(RedirectToAction("Index"));
            }

            return(Json(model));
        }
Exemple #3
0
        public IActionResult GeneralExpense(ExpenseAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ViewBag.ExpenseCategoryId = new SelectList(_db.ExpenseCategories.ddl(), "value", "label", model.ExpenseCategoryId);

            var response = _expense.AddCost(model, User.Identity.Name, User.IsInRole("admin"));

            if (response.IsSuccess)
            {
                return(RedirectToAction("GeneralExpense", new { response.Message }));
            }

            return(View(model));
        }
Exemple #4
0
        public DbResponse AddCost(ExpenseAddModel model, string userName, bool isApproved)
        {
            try
            {
                var registrationId = _db.Registrations.GetRegID_ByUserName(userName);
                var voucherNo      = _db.Institutions.GetVoucherCountdown() + 1;

                _db.Expenses.AddCustom(model, registrationId, voucherNo, isApproved);

                if (isApproved && model.AccountId != null)
                {
                    _db.Account.BalanceSubtract(model.AccountId.Value, model.ExpenseAmount);
                }

                _db.Institutions.IncreaseVoucherCount();
                _db.SaveChanges();

                return(new DbResponse(true, "Added Successfully"));
            }
            catch (Exception e)
            {
                return(new DbResponse(false, e.Message));
            }
        }
        public async Task <IActionResult> Post([FromBody] ExpenseAddModel value)
        {
            var userId = _validateHelper.GetUserId(HttpContext);

            try
            {
                var model = await _expenseService.AddAsync(userId, value);

                if (model == null)
                {
                    return(BadRequest());
                }

                return(Ok(model));
            }
            catch (ForbidException)
            {
                return(Forbid());
            }
            catch (KeyNotFoundException)
            {
                return(BadRequest());
            }
        }
Exemple #6
0
        public async Task <ExpenseManageModel> AddAsync(string user, ExpenseAddModel model)
        {
            if (model == null)
            {
                return(null);
            }

            // label already test the group is valid
            var labelModel = await _labelService.GetByIdAsync(user, model.LabelId);

            if (labelModel == null)
            {
                throw new KeyNotFoundException();
            }

            var objToAdd = _mapper.Map <ExpenseModel>(model);

            _unitOfWork.BeginTransaction();
            var objAdded = await _repository.AddAsync(objToAdd);

            var result = await _unitOfWork.CommitAsync();

            return(result > 0 ? _mapper.Map <ExpenseManageModel>(objAdded) : null);
        }