public ActionResult Editar(int Id)
        {
            MarketPlaceEntities entities = new MarketPlaceEntities();
            EditarProductoVM    model    = new EditarProductoVM();

            try
            {
                Producto producto = entities.Producto.Find(Id);

                if (producto != null)
                {
                    model.Id              = producto.Id;
                    model.Nombre          = producto.Nombre;
                    model.Precio          = producto.Precio;
                    model.Stock           = producto.Stock;
                    model.FechaExpiracion = producto.FechaExpiracion;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                entities.Dispose();
            }

            return(View(model));
        }
        public ActionResult Editar(EditarProductoVM model)
        {
            MarketPlaceEntities entities = new MarketPlaceEntities();

            try
            {
                if (ModelState.IsValid)
                {
                    Producto producto = entities.Producto.Find(model.Id);

                    producto.Nombre                = model.Nombre;
                    producto.Precio                = model.Precio;
                    producto.Stock                 = model.Stock;
                    producto.FechaExpiracion       = model.FechaExpiracion;
                    entities.Entry(producto).State = System.Data.EntityState.Modified;
                    entities.SaveChanges();
                    return(Redirect("~/Producto"));
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                entities.Dispose();
            }

            return(View(model));
        }
        public ActionResult Nuevo(NuevoProductoVM model)
        {
            MarketPlaceEntities entities = new MarketPlaceEntities();

            try
            {
                if (ModelState.IsValid)
                {
                    int Id = entities.Producto.Count() + 1;

                    Producto producto = new Producto();
                    producto.Id              = model.Id;
                    producto.Nombre          = model.Nombre;
                    producto.Precio          = model.Precio;
                    producto.Stock           = model.Stock;
                    producto.FechaExpiracion = model.FechaExpiracion;
                    entities.Producto.Add(producto);
                    entities.SaveChanges();
                    return(Redirect("~/Producto"));
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                entities.Dispose();
            }

            return(View(model));
        }
        //
        // GET: /Product/

        public ActionResult Index()
        {
            MarketPlaceEntities   entities       = new MarketPlaceEntities();
            List <ListProductoVM> lstProductosVM = new List <ListProductoVM>();

            try
            {
                lstProductosVM = (from d in entities.Producto
                                  select new ListProductoVM
                {
                    Id = d.Id,
                    Nombre = d.Nombre,
                    Precio = d.Precio,
                    Stock = d.Stock,
                    FechaExpiracion = d.FechaExpiracion
                }).ToList();
            }
            catch (Exception ex)
            {
            }
            finally{
                entities.Dispose();
            }

            return(View(lstProductosVM));
        }
Пример #5
0
        public OrderDataBase()
        {
            dbContext = new MarketPlaceEntities();
            var OrderDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <OrderDataDTO, Order>();
            });
            var VariantDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <CartVariantDTO, OrderPlacedVariant>()
                .ForMember(s => s.ID, opt => opt.Ignore())
                .ForMember(s => s.OrderPlacedID, opt => opt.Ignore())
                .ForMember(s => s.OrderPlaced, opt => opt.Ignore())
                .ForMember(s => s.Variant, opt => opt.Ignore());
            });
            var MyOrderDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <OrderPlaced, OrderPlacedDTO>();
                cfg.CreateMap <Order, OrderDTO>();
                cfg.CreateMap <OrderPlacedVariant, OrderPlacedVariantDTO>();
            });
            var MyOrderDeatilsDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <OrderPlacedVariant, OrderPlacedVariantDTO>();
            });

            OrderDataMapper      = new Mapper(OrderDTOConfig);
            VariantMapper        = new Mapper(VariantDTOConfig);
            MyOrderMapper        = new Mapper(MyOrderDTOConfig);
            MyOrderDeatilsMapper = new Mapper(MyOrderDeatilsDTOConfig);
        }
Пример #6
0
        public AddressDatabase()
        {
            dbContext = new MarketPlaceEntities();
            var AddressConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Address, AddressDTO>();
            });
            var AddressDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <AddressDTO, Address>();
            });

            AddresssMapper = new Mapper(AddressConfig);
            AddressAdded   = new Mapper(AddressDTOConfig);
        }
Пример #7
0
        public UserDatabase()
        {
            dbContext = new MarketPlaceEntities();
            var UserDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <User, UserInfoDTO>();
            });
            var AddUserConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <UserDTO, User>();
            });
            var UserDbConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <User, UserDTO>();
            });

            userMapper        = new Mapper(UserDTOConfig);
            AddUserMapper     = new Mapper(AddUserConfig);
            UserDetailsMapper = new Mapper(UserDbConfig);
        }
Пример #8
0
        public CategoryProductDatabase()
        {
            dbContext = new MarketPlaceEntities();
            var categoryDTOConfig = new MapperConfiguration(cfg => {
                cfg.CreateMap <Category, CategoryDTO>();
            });
            var categoryProductDTOConfig = new MapperConfiguration(cfg => {
                cfg.CreateMap <Category, CategoryDTO>();
                cfg.CreateMap <Product, ProductDTO>();
                cfg.CreateMap <Variant, VariantDTO>();
                cfg.CreateMap <VariantImage, VariantImageDTO>();
            });
            var ProductsCategoryDTOMapper = new MapperConfiguration(cfg => {
                cfg.CreateMap <Product, ProductDTO>();
                cfg.CreateMap <Variant, VariantDTO>();
                cfg.CreateMap <VariantImage, VariantImageDTO>();
            });

            ProductsFromCategoryMapper = new Mapper(ProductsCategoryDTOMapper);
            categoryListMapper         = new Mapper(categoryProductDTOConfig);
        }
Пример #9
0
        public AddVariantDataBase()
        {
            dbContext = new MarketPlaceEntities();
            var VariantDTOConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Variant, VariantDTO>();
            });
            var userOrderConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <OrderPlacedVariant, OrderPlacedVariantDTO>();
            });
            var cartConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <CartVariantDTO, CartVariantMapping>()
                .ForMember(dest => dest.CartID,
                           opts => opts.MapFrom(src => src.CartID));
            });
            var cartPresentConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <CartVariantMapping, CartOrderVariantDTO>()
                .ForMember(dest => dest.UserID,
                           opts => opts.MapFrom(src => src.CartID));
            });

            var cartVariantConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <CartVariantMapping, CartVariantDTO>();
                cfg.CreateMap <Variant, VariantDTO>();
                cfg.CreateMap <Product, ProductDTO>();
            });

            VariantMapper     = new Mapper(VariantDTOConfig);
            OrderUserMapper   = new Mapper(userOrderConfig);
            cartOrderMapper   = new Mapper(cartConfig);
            cartCheckerMapper = new Mapper(cartPresentConfig);
            cartVariantMapper = new Mapper(cartVariantConfig);
        }
        public ActionResult Eliminar(int Id)
        {
            MarketPlaceEntities entities = new MarketPlaceEntities();

            try
            {
                Producto producto = entities.Producto.Find(Id);

                if (producto != null)
                {
                    entities.Producto.Remove(producto);
                    entities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                entities.Dispose();
            }

            return(Redirect("~/Producto"));
        }