Exemplo n.º 1
0
        public HttpResponseMessage PostSales(Sale sale)
        {
            if (sale == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            try
            {
                var user = db.Users.First(x => x.Email == User.Identity.Name);
                sale.Customer = user.Customer;
                sale.SaleDate = DateTime.Now;
                db.Sales.Add(sale);
                db.SaveChanges();

                var result = sale;
                return(Request.CreateResponse(HttpStatusCode.Created, result));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao cadastrar compra."));
            }
        }
Exemplo n.º 2
0
 public void Create(User user)
 {
     _context.Users.Add(user);
     _context.SaveChanges();
 }