public void UpdateCategorySize(int id, string name)
    {
        try
        {
            name = name.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible registrar la Categoría de Talla");
        }

        CategorySizesDAO    dao                = new CategorySizesDAO();
        List <CategorySize> categorySizes      = GetAllCategorySizes();
        CategorySize        updateCategorySize = categorySizes.Find(c => c.id.Equals(id));

        if (updateCategorySize != null)
        {
            if (categorySizes.FindAll(c => (c.name.ToUpperInvariant().Equals(name.ToUpperInvariant())) && (c.id != id)).Count > 0)
            {
                throw new Exception("Ya existe una Categoría Talla con este nombre");
            }

            updateCategorySize.name = name;

            int result = dao.UpdateCategorySize(updateCategorySize);
            if (result < 1)
            {
                throw new Exception("No es posible actualizar la Categoría de Talla");
            }
        }
        else
        {
            throw new Exception("El id de la Categoría Talla a actualizar no es válido");
        }
    }
 private void AddParameters(CategorySize categorySize, Database database, DbCommand command)
 {
     database.AddInParameter(command, "@pId", DbType.Int32, categorySize.id);
     database.AddInParameter(command, "@pName", DbType.String, categorySize.name);
     database.AddParameter(command, "@pIdReturn", DbType.Int32, ParameterDirection.ReturnValue
                           , null, DataRowVersion.Default, null);
 }
    public void InsertCategorySize(string name)
    {
        try
        {
            name = name.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible registrar la Categoría de Talla");
        }

        CategorySizesDAO    dao           = new CategorySizesDAO();
        List <CategorySize> categorySizes = GetAllCategorySizes();

        if (categorySizes.FindAll(c => (c.name.ToUpperInvariant().Equals(name.ToUpperInvariant()))).Count > 0)
        {
            throw new Exception("Ya existe una Categoría de Talla con este nombre");
        }

        CategorySize newCategorySize = new CategorySize();

        newCategorySize.name = name;
        int result = dao.CreateCategorySize(newCategorySize);

        if (result < 1)
        {
            throw new Exception("No es posible registrar la Categoría de Talla");
        }
    }
        public ActionResult DeleteConfirmed(int id)
        {
            CategorySize categorySize = db.CategorySizes.Find(id);

            db.CategorySizes.Remove(categorySize);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
    public CategorySize GetCategorySize(int id)
    {
        CategorySize     categorySize = new CategorySize();
        CategorySizesDAO dao          = new CategorySizesDAO();

        categorySize = dao.GetCategorySize(id);
        return(categorySize);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int productId = -1;

        if (!IsPostBack)
        {
            try
            {
                productId = Convert.ToInt32(Request.QueryString["productId"]);
                CtrlProducts ctrlProducts = new CtrlProducts();
                Product      product      = ctrlProducts.GetProduct(productId);

                if (product != null && product.id > 0)
                {
                    lblNombreProducto.Text = product.name;
                    lblDescripcion.Text    = product.shortDescription;

                    CtrlProductTypes ctrlProductTypes = new CtrlProductTypes();
                    ProductType      productType      = ctrlProductTypes.GetProductType(product.productTypeId);

                    if (productType != null && productType.id > 0)
                    {
                        CtrlCategorySizes ctrlCategorySizes = new CtrlCategorySizes();
                        CategorySize      categorySize      = ctrlCategorySizes.GetCategorySize(productType.categorySizeId);

                        CtrlSizes   ctrlSizes    = new CtrlSizes();
                        List <Size> listAllSizes = ctrlSizes.GetAllSizes();
                        listAllSizes = listAllSizes.FindAll(s => s.categorySizeId.Equals(categorySize.id));

                        CtrlStockSizes   ctrlStockSizes    = new CtrlStockSizes();
                        List <StockSize> listAllStockSizes = ctrlStockSizes.GetAllStockSizes();
                        listAllStockSizes = listAllStockSizes.FindAll(ss => ss.productId.Equals(product.id));

                        foreach (Size size in listAllSizes)
                        {
                            StockSize stockSize = listAllStockSizes.Find(ss => ss.sizeId.Equals(size.id));
                            if (stockSize == null)
                            {
                                StockSize newStockSize = new StockSize();
                                newStockSize.productId = product.id;
                                newStockSize.sizeId    = size.id;
                                newStockSize.stock     = 0;
                                ctrlStockSizes.InsertStockSize(newStockSize.productId, newStockSize.sizeId, newStockSize.stock);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Response.Redirect("Products.aspx");
            }
        }
    }
 public ActionResult Edit([Bind(Include = "Id,CategoryId,SectionId,SizeId")] CategorySize categorySize)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categorySize).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", categorySize.CategoryId);
     ViewBag.SectionId  = new SelectList(db.Sections, "Id", "Name", categorySize.SectionId);
     ViewBag.SizeId     = new SelectList(db.Sizes, "Id", "Name", categorySize.SizeId);
     return(View(categorySize));
 }
        // GET: Admin/CategorySizes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategorySize categorySize = db.CategorySizes.Find(id);

            if (categorySize == null)
            {
                return(HttpNotFound());
            }
            return(View(categorySize));
        }
        // GET: Admin/CategorySizes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategorySize categorySize = db.CategorySizes.Find(id);

            if (categorySize == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", categorySize.CategoryId);
            ViewBag.SectionId  = new SelectList(db.Sections, "Id", "Name", categorySize.SectionId);
            ViewBag.SizeId     = new SelectList(db.Sizes, "Id", "Name", categorySize.SizeId);
            return(View(categorySize));
        }
    public void DeleteCategorySize(int id)
    {
        CategorySizesDAO dao = new CategorySizesDAO();
        CategorySize     deleteCategorySize = dao.GetCategorySize(id);

        if (deleteCategorySize != null)
        {
            int result = dao.DeleteCategorySize(deleteCategorySize);
            if (result < 1)
            {
                throw new Exception("No es posible eliminar la Categoría de Talla, por favor verificar que no existan asociaciones a la Categoría de Talla");
            }
        }
        else
        {
            throw new Exception("El id de la Categoría Talla a eliminar no es válido");
        }
    }
        public int DeleteCategorySize(CategorySize categorySize)
        {
            int result = -1;

            try
            {
                Database  database = DatabaseFactory.CreateDatabase();
                DbCommand command  = database.GetStoredProcCommand(storedProcedureName);
                database.AddInParameter(command, "@pOperation", DbType.Int32, 5);
                AddParameters(categorySize, database, command);
                result = database.ExecuteNonQuery(command);
            }
            catch (Exception exc)
            {
                //Crear Exception
            }
            return(result);
        }
        public CategorySize GetCategorySize(int id)
        {
            CategorySize categorySize = null;

            try
            {
                Database  database = DatabaseFactory.CreateDatabase();
                DbCommand command  = database.GetStoredProcCommand(storedProcedureName);
                database.AddInParameter(command, "@pOperation", DbType.Int32, 3);
                database.AddInParameter(command, "@pId", DbType.Int32, id);
                DataSet dsAllCategorySizes = database.ExecuteDataSet(command);
                if (dsAllCategorySizes != null && dsAllCategorySizes.Tables.Count > 0)
                {
                    categorySize = DAOUtilities.FillEntities <CategorySize>(dsAllCategorySizes.Tables[0])
                                   .FirstOrDefault();
                }
            }
            catch (Exception exc)
            {
                //Crear Exception
            }
            return(categorySize);
        }
Beispiel #13
0
            public async Task <CatlogDto> Handle(Command request, CancellationToken cancellationToken)
            {
                //var test = request.test;

                var catalog = await _context.Catalogs
                              .FindAsync(request.Id);

                if (catalog == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Catalog = "Not found" });
                }

                var CurrentUsername = _userAccessor.GetCurrentUsername();

                float price = 0;

                if (!float.TryParse(request.Price, out price))
                {
                    throw new Exception("invalid Price");
                }

                if (CurrentUsername.ToLower().ToString() == "admin" || catalog.Supplier.UserName == CurrentUsername)
                {
                    var category = await _context.Categories.SingleOrDefaultAsync(x =>
                                                                                  x.Id == request.CategoryId);

                    #region CategoryColores

                    //delete all existing entries
                    _context.CategoryColores.RemoveRange(catalog.Colores);

                    //Add existing entries
                    if (request.Colores != null)
                    {
                        foreach (string c in request.Colores)
                        {
                            var color = new CategoryColores {
                                configid = c
                            };
                            catalog.Colores.Add(color);
                        }
                    }

                    #endregion CategoryColores

                    #region Sizes

                    //delete all existing entries

                    _context.CategorySize.RemoveRange(catalog.Sizes);

                    // Add existing entries
                    if (request.Sizes != null)
                    {
                        foreach (CategorySize s in request.Sizes)
                        {
                            var size = new CategorySize {
                                configid = s.configid, Title = s.Title, Qty = s.Qty
                            };
                            catalog.Sizes.Add(size);
                        }
                    }


                    #endregion Sizes


                    if (category != null)
                    {
                        catalog.Category = category;
                    }
                    catalog.DisplayName = request.DisplayName ?? catalog.DisplayName;
                    catalog.Description = request.Description ?? catalog.Description;
                    catalog.Price       = price;


                    // _context.Entry(cl).State = EntityState.Modified;  //.Entry(user).State = EntityState.Added; /
                    var success = await _context.SaveChangesAsync() > 0;

                    //if (success) return Unit.Value;
                    if (success)
                    {
                        var toReturn = _mapper.Map <Catalog, CatlogDto>(catalog);
                        return(toReturn);
                    }
                }
                else
                {
                    throw new Exception("Unauthorized access");
                }


                throw new Exception("Problem saving changes");
            }
Beispiel #14
0
            public async Task <CatlogDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var supplier = await _context.Users.SingleOrDefaultAsync(x =>
                                                                         x.UserName == _userAccessor.GetCurrentUsername());

                var category = await _context.Categories.SingleOrDefaultAsync(x =>
                                                                              x.Id == request.CategoryId);

                //CategoryId
                float price = 0;

                if (!float.TryParse(request.Price, out price))
                {
                    throw new Exception("invalid Price");
                }



                var cl = new List <CategoryColores>();

                //Add existing entries
                if (request.Colores != null)
                {
                    if (request.Colores != null)
                    {
                        foreach (string c in request.Colores)
                        {
                            var color = new CategoryColores
                            {
                                //Id = Guid.NewGuid(),
                                //CatlogId = request.Id,
                                configid = c
                            };
                            cl.Add(color);
                        }
                    }
                }

                var cz = new List <CategorySize>();

                if (request.Sizes != null)
                {
                    foreach (CategorySize s in request.Sizes)
                    {
                        var size = new CategorySize
                        {
                            configid = s.configid, Title = s.Title, Qty = s.Qty
                        };
                        //{
                        //    Id = Guid.NewGuid(),
                        //    Title = s.Title,
                        //    Qty = s.Qty

                        //};
                        cz.Add(size);
                    }
                }

                var catalog = new Catalog
                {
                    //Id = request.Id,
                    DisplayName = request.DisplayName,
                    Description = request.Description,
                    Supplier    = supplier,
                    Category    = category,
                    Price       = price,
                    Colores     = cl,
                    Sizes       = cz
                };

                _context.Catalogs.Add(catalog);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    var toReturn = _mapper.Map <Catalog, CatlogDto>(catalog);
                    return(toReturn);
                }
                //return Unit.Value;

                //var toReturn = _mapper.Map<Catalog, CatlogDto>(catalog);
                //return toReturn;

                throw new Exception("Problem saving changes");
            }