예제 #1
0
        public async Task <IActionResult> PutCrediario(int id, Crediario crediario)
        {
            if (id != crediario.IdCrediario)
            {
                return(BadRequest());
            }

            _context.Entry(crediario).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CrediarioExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public virtual Crediario SaveCrediario(CrediarioViewModel modelView)
        {
            try
            {
                Crediario entity = new Crediario
                {
                    PersonId        = modelView.PersonId,
                    UserId          = modelView.UserId,
                    EnableCrediario = modelView.EnableCrediario
                };
                _rep.Insert(entity);

                if (modelView.Sales != null && modelView.Sales.Count() > 0)
                {
                    modelView.Sales.ToList().ForEach(x => _appSale.SaveSale(new SaleViewModel {
                        Value = x.Value, EnableSale = x.EnableSale, PurchaseDate = x.PurchaseDate, CreadiarioId = entity.Id
                    }));
                }
                return(entity);
            }
            catch (Exception ex)
            {
                throw new ValidationException();
            }
        }
예제 #3
0
        public async Task <ActionResult <Crediario> > PostCrediario(Crediario crediario)
        {
            _context.Crediario.Add(crediario);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCrediario", new { id = crediario.IdCrediario }, crediario));
        }
예제 #4
0
        public void TaxarOValorFinal()
        {
            const double TAXA_CREDIARIO = 0.015;
            var          valorEsperado  = 1000 * (1 + TAXA_CREDIARIO);
            var          crediario      = new Crediario(1000, 12, lista);

            Assert.Equal(valorEsperado, crediario.ValorFinal());
        }
예제 #5
0
        public void DeleteCrediario(int id)
        {
            Crediario crediario = _rep.Get(id);

            if (crediario != null)
            {
                _rep.Delete(crediario);
            }
        }
예제 #6
0
        public void DeleteCrediario(int id)
        {
            Crediario crediario = _rep.Get(id);

            if (crediario != null)
            {
                crediario.EnableCrediario = false;
                _rep.Update(crediario);
            }
        }
예제 #7
0
        public virtual Crediario EditCrediario(CrediarioViewModel view)
        {
            try
            {
                //List<Sale> sale = new List<Sale>();
                //for (int i = 0; i < view.Sales.Count(); i++)
                //{
                //    sale.Add(new Sale
                //    {
                //        Id = (int)view.Sales[i]?.Id.Value,
                //        CreadiarioId = (int)view?.Sales[i]?.CreadiarioId,
                //        EnableSale = view.Sales[i].EnableSale,
                //        PurchaseDate = view.Sales[i].PurchaseDate,
                //        Value   = view.Sales[i].Value
                //    });
                //}

                Crediario crediario = _rep.Get(view.Id.Value);

                if (crediario != null)
                {
                    crediario.PersonId = view.PersonId;
                    crediario.UserId   = view.UserId;

                    _rep.Update(crediario);
                }

                if (view.Sales != null && view.Sales.Count() > 0)
                {
                    view.Sales.ToList().ForEach(x => _appSale.EditSale(new SaleViewModel {
                        Id = x.Id, Value = x.Value, EnableSale = x.EnableSale, PurchaseDate = x.PurchaseDate, CreadiarioId = crediario.Id
                    }));
                }

                return(crediario);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #8
0
        public virtual Crediario GetById(int id)
        {
            try
            {
                var entity = _rep.Get(id);

                Crediario crediario = new Crediario
                {
                    Id       = entity.Id,
                    PersonId = entity.PersonId,
                    UserId   = entity.UserId,
                    Sales    = entity.Sales
                };

                return(crediario);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #9
0
        public virtual Crediario EditCrediario(CrediarioViewModel view)
        {
            try
            {
                Crediario crediario = _rep.Get(view.Id.Value);

                if (crediario != null)
                {
                    crediario.PersonId          = view.PersonId;
                    crediario.Rate              = view.Rate;
                    crediario.Sales             = view.Sales;
                    crediario.UserId            = view.UserId;
                    crediario.SchedulingPayment = view.SchedulingPayment;

                    _rep.Update(crediario);
                }

                return(crediario);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #10
0
        public void IdExistente()
        {
            var crediario = new Crediario(1000.0, 1, lista);

            Assert.True(crediario.IdTransacao > 0);
        }
예제 #11
0
        public void LimitarAsParcelas()
        {
            Crediario crediario;

            Assert.Throws <ArgumentException>(() => crediario = new Crediario(1000, 25, lista));
        }