private bool DoUpdateCustomer(CustomerViewModel model)
        {
            var svc     = new CustomerAppSvcGeneric();
            var updated = svc.Update(model.GetEntity());

            return(updated != null);
        }
        public IHttpActionResult Patch(CustomerViewModel model)
        {
            if (!model.id.HasValue || model.id.Value < 0)
            {
                return(BadRequest());
            }

            var svc      = new CustomerAppSvcGeneric();
            var toUpdate = svc.Get(model.id.Value);

            if (toUpdate == null)
            {
                return(NotFound());
            }

            try {
                toUpdate.Name        = model.customerName;
                toUpdate.ContactName = model.contactName;
                var result = svc.Update(toUpdate);

                return(Ok(result));
            }
            catch (Exception ex) {
                return(InternalServerError(ex));
            }
        }
        private bool DoCreateCustomer(CustomerViewModel model)
        {
            var svc     = new CustomerAppSvcGeneric();
            var created = svc.Create(model.GetEntity());

            return(created.Id > 0);
        }
        public ActionResult Delete(int id)
        {
            var service = new CustomerAppSvcGeneric();
            var delete  = service.Delete(id);

            return(RedirectToAction("List"));
        }
        public void FindByTestGetAll()
        {
            var svc    = new CustomerAppSvcGeneric();
            var result = svc.FindBy(null);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
        public ActionResult List()
        {
            var service      = new CustomerAppSvcGeneric();
            var listCustomer = service.FindBy(null);

            ViewBag.listCustomer = listCustomer;

            return(View());
        }
        public void FindByTestGetByName()
        {
            var svc    = new CustomerAppSvcGeneric();
            var result = svc.FindBy(new Customer {
                Name = "boteco"
            });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
        private CustomerViewModel GetViewModelForEdit(int id)
        {
            var customer = new CustomerAppSvcGeneric().Get(id);

            return(new CustomerViewModel {
                CustomerName = customer.Name,
                Cnpj = customer.Cnpj,
                ContactName = customer.ContactName,
                IsEdit = true,
                Id = id
            });
        }
        public void DeleteTestInvalido()
        {
            CustomerAppSvcGeneric rep = new CustomerAppSvcGeneric();

            Customer objCustomer = new Customer {
                Id = 4
            };

            var result = rep.Delete(objCustomer.Id);

            Assert.IsNotNull(result);
            Assert.IsFalse(result);
        }
        public void UpdateTest()
        {
            var objCustomer = new Customer()
            {
                Id          = 2,
                ContactName = "Florisvaldo"
            };

            var svc             = new CustomerAppSvcGeneric();
            var customerUpdated = svc.Update(objCustomer);

            Assert.IsNotNull(customerUpdated);
            Assert.IsTrue(customerUpdated.Id > 0);
        }
        public void CreateTestInvalido()
        {
            var objCustomer = new Customer {
                Name        = null,
                ContactName = "Zézim",
                Cnpj        = 32191161000110,
                IsActive    = true,
                Projects    = null
            };

            var srv    = new CustomerAppSvcGeneric();
            var result = srv.Create(objCustomer);

            Assert.IsNull(result);
            //Assert.IsTrue(result.Count() == 0);
        }
        public void CreateTestValido()
        {
            var objCustomer = new Customer {
                Name        = "Boteco do Zé - ME",
                ContactName = "Zézim",
                Cnpj        = 32191161000110,
                IsActive    = true,
                Projects    = null
            };

            var srv    = new CustomerAppSvcGeneric();
            var result = srv.Create(objCustomer);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
        }
        public IHttpActionResult Get(int id)
        {
            if (id < 0)
            {
                return(BadRequest());
            }

            var svc      = new CustomerAppSvcGeneric();
            var customer = svc.Get(id);

            if (customer == null)
            {
                return(NotFound());
            }

            return(Ok(customer));
        }
        public IHttpActionResult Delete(int id)
        {
            if (id < 0)
            {
                return(BadRequest());
            }

            var svc      = new CustomerAppSvcGeneric();
            var customer = svc.Get(id);

            if (customer == null)
            {
                return(NotFound());
            }

            var result = svc.Delete(id);

            return(result ? StatusCode(HttpStatusCode.NoContent) : StatusCode(HttpStatusCode.InternalServerError));
        }
Пример #15
0
        public ActionResult New()
        {
            List <SelectListItem> selectItens = new List <SelectListItem>();
            var service      = new CustomerAppSvcGeneric();
            var listCustomer = service.FindBy(null).ToList();



            foreach (var item in listCustomer)
            {
                selectItens.Add(new SelectListItem {
                    Value = item.Id.ToString(),
                    Text  = item.Name
                });
            }

            ViewBag.Clientes = selectItens;

            return(View("ProjectControl"));
        }
        public IHttpActionResult Create(CustomerViewModel model)
        {
            if (
                string.IsNullOrEmpty(model.customerName) ||
                string.IsNullOrEmpty(model.contactName) ||
                (model.cnpj == 0 || model.cnpj.ToString().Length < 14)
                )
            {
                return(BadRequest());
            }

            try {
                var svc         = new CustomerAppSvcGeneric();
                var newCustomer = svc.Create(model.GetCustomer());

                return(Ok(newCustomer));
            }
            catch (Exception e) {
                return(InternalServerError(e));
            }
        }