Exemplo n.º 1
0
        public IActionResult AddBill(AddEditBillViewModel model)
        {
            if (model != null && model.Bill != null && ModelState.IsValid)
            {
                if (float.TryParse(model.Bill.Amount.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var amount))
                {
                    var entity = new BillEntity
                    {
                        CreatedBy   = HttpContext.User.Identity.Name,
                        CreatedDate = DateTime.Now,
                        Description = model.Bill.Description,
                        PersonId    = model.Bill.PersonId,
                        Amount      = amount,
                        BillDate    = model.Bill.BillDate.Value,
                        BillId      = model.Bill.Id
                    };
                    if (entity.BillId > 0)
                    {
                        _billsService.UpdateBill(entity);
                    }
                    else
                    {
                        _billsService.AddBill(entity);
                    }
                }
            }

            return(RedirectToAction(nameof(BillsList)));
        }
Exemplo n.º 2
0
        public IActionResult AddEditBill(int id)
        {
            var bill      = _billsService.GetBillById(id);
            var viewModel = new AddEditBillViewModel
            {
                PeopleList = _peopleService.GetAllPeople()
                             .Select(s => new SelectListItem(s.Name, s.PersonId.ToString()))
                             .ToList()
            };

            viewModel.Bill = bill != null ? new BillModel
            {
                Id          = bill.BillId,
                Amount      = bill.Amount.ToString(CultureInfo.InvariantCulture),
                BillDate    = bill.BillDate,
                Description = bill.Description,
                PersonId    = bill.PersonId,
                PersonName  = bill.Person.Name
            } : new BillModel();


            return(PartialView("_AddEditBill", viewModel));
        }