Exemplo n.º 1
0
        public IHttpActionResult PutCategory(int id, Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.CategoryID)
            {
                return(BadRequest());
            }

            db.Entry(category).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "DocumentTypeID,Description")] DocumentType documenttype)
        {
            if (ModelState.IsValid)
            {
                db.DocumentTypes.Add(documenttype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(documenttype));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ProductID,Description,Price,LastBuy,Stock,Remarks")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
        public ActionResult Create([Bind(Include = "CategoryID,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "SupplierID,Name,ContactFirstName,ContactLastName,Phone,Address,Email")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplier));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "CustomerID,Name,LastName,Phone,Address,Email,Document,DocumentTypeID")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", customer.DocumentTypeID);
            return(View(customer));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "EmployeeID,FirstName,LastName,Salary,BonusPercent,DateOfBirth,StartTime,Email,URL,DocumentTypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", employee.DocumentTypeID);
            return(View(employee));
        }
Exemplo n.º 8
0
 public void GuardarRolAdmin()
 {
     _tiendaContext.Roles.Add(new Rol {
         Nombre = "Administrador"
     });
     _tiendaContext.SaveChanges();
 }
Exemplo n.º 9
0
        public UsuarioController(TiendaVirtualContext context)
        {
            _context = context;
            var usuarioResponse = _context.Usuarios.Find("*****@*****.**");

            if (usuarioResponse == null)
            {
                var key = Seguridad.RandomString(16);
                _context.Usuarios.Add(new Usuario()
                {
                    Email = "*****@*****.**", Estado = "Activo", KeyDesEncriptarPassword = key, Password = Seguridad.Encriptar("adminABC", key), Role = "LIDER"
                });
                _context.SaveChanges();
            }

            _serviceUsuario = new UsuarioService(context);
        }
Exemplo n.º 10
0
        public LoginController(TiendaVirtualContext tiendaContext)
        {
            _tiendaContext = tiendaContext;
            var admin = _tiendaContext.Roles.Where((r) => r.Nombre == "Administrador").FirstOrDefault();

            if (admin == null)
            {
                GuardarRolAdmin();
                _tiendaContext.Usuarios.Add(new Entity.Usuario()
                {
                    IdRol         = _tiendaContext.Roles.Where((r) => r.Nombre == "Administrador").FirstOrDefault().Id,
                    Contrasena    = Hash.GetSha256("admin"),
                    NombreUsuario = "admin"
                });
                var i = _tiendaContext.SaveChanges();
            }
            usuarioService = new UsuarioService(tiendaContext);
        }
Exemplo n.º 11
0
        public ActionResult NewOrder(OrderView orderView)
        {
            orderView = Session["OrderView"] as OrderView;
            var customerId = int.Parse(Request["CustomerID"]);

            if (customerId == 0)
            {
                var list = db.Customers.ToList();
                list.Add(new Customer {
                    CustomerID = 0, Name = "[Seleccione un Cliente...]"
                });
                list = list.OrderBy(c => c.FullName).ToList();
                ViewBag.CustomerID = new SelectList(list, "CustomerID", "FullName");
                ViewBag.Error      = "Debe de seleccionar un Cliente.";
                return(View(orderView));
            }

            var customer = db.Customers.Find(customerId);

            if (customer == null)
            {
                var lista2 = db.Customers.ToList();
                lista2.Add(new Customer {
                    CustomerID = 0, Name = "[Seleccione un Cliente...]"
                });
                lista2             = lista2.OrderBy(c => c.FullName).ToList();
                ViewBag.CustomerID = new SelectList(lista2, "CustomerID", "FullName");
                ViewBag.Error      = "Cliente inexistente.";
                return(View(orderView));
            }

            if (orderView.Products.Count == 0)
            {
                var lista3 = db.Customers.ToList();
                lista3.Add(new Customer {
                    CustomerID = 0, Name = "[Seleccione un Cliente...]"
                });
                lista3             = lista3.OrderBy(c => c.FullName).ToList();
                ViewBag.CustomerID = new SelectList(lista3, "CustomerID", "FullName");
                ViewBag.Error      = "Debe de añadir productos a la orden.";
                return(View());
            }

            int orderId = 0;

            using (var transaccion = db.Database.BeginTransaction()) {
                try
                {
                    var _order = new Order
                    {
                        CustomerID  = customerId,
                        OrderDate   = DateTime.Now,
                        OrderStatus = OrderStatus.Created
                    };

                    db.Orders.Add(_order);
                    db.SaveChanges();

                    orderId = db.Orders.ToList().Select(o => o.OrderID).Max();

                    foreach (var item in orderView.Products)
                    {
                        var orderDetail = new OrderDetails
                        {
                            ProductID   = item.ProductID,
                            OrderID     = orderId,
                            Description = item.Description,
                            Price       = item.Price,
                            Quantity    = item.Quantity
                        };
                        db.OrderDetails.Add(orderDetail);
                    }
                    db.SaveChanges();
                    transaccion.Commit();
                }
                catch (Exception ex)
                {
                    transaccion.Rollback();
                    ViewBag.Error = "ERROR: " + ex.Message;
                    var lista4 = db.Customers.ToList();
                    lista4.Add(new Customer {
                        CustomerID = 0, Name = "[Seleccione un Cliente...]"
                    });
                    lista4             = lista4.OrderBy(c => c.FullName).ToList();
                    ViewBag.CustomerID = new SelectList(lista4, "CustomerID", "FullName");
                }
            }

            ViewBag.Message = string.Format("La orden {0} fue guardada con exito.", orderId);

            var lista = db.Customers.ToList();

            lista.Add(new Customer {
                CustomerID = 0, Name = "[Seleccione un Cliente...]"
            });
            lista = lista.OrderBy(c => c.FullName).ToList();
            ViewBag.CustomerID = new SelectList(lista, "CustomerID", "FullName");

            orderView            = new OrderView();
            orderView.Customer   = new Customer();
            orderView.Products   = new List <ProductOrder>();
            Session["OrderView"] = orderView;

            return(View(orderView));
        }