Exemplo n.º 1
0
        void ReleaseDesignerOutlets()
        {
            if (CategoryCountLabel != null)
            {
                CategoryCountLabel.Dispose();
                CategoryCountLabel = null;
            }

            if (CategoryImage != null)
            {
                CategoryImage.Dispose();
                CategoryImage = null;
            }

            if (CategoryImageOverlay != null)
            {
                CategoryImageOverlay.Dispose();
                CategoryImageOverlay = null;
            }

            if (CategoryName != null)
            {
                CategoryName.Dispose();
                CategoryName = null;
            }
        }
Exemplo n.º 2
0
            public void Bind(IOrderContent model)
            {
                CellContentRootView?.SetBackgroundColor(ColorConstants.BackroundCell, 5);

                CategoryImage?.SetImageFromUrl(model.ImagePath);

                if (!ItemNameText.IsNull())
                {
                    ItemNameText.Text = model.OrderName;
                    ItemNameText?.SetTextColor(ColorConstants.WhiteColor);
                    ItemNameText.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (!PriceText.IsNull())
                {
                    PriceText.Text = "€" + model.Price * Convert.ToInt32(model.Quantity);
                    PriceText?.SetTextColor(ColorConstants.SelectorHome);
                    PriceText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (QuantityText.IsNull())
                {
                    return;
                }
                QuantityText.Text = model.Quantity + " pcs";
                QuantityText?.SetTextColor(ColorConstants.WhiteColor);
                QuantityText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
            }
Exemplo n.º 3
0
        public ActionResult AddCategory(Category cat, List <HttpPostedFileBase> images)
        {
            if (ModelState.IsValid)
            {
                var i = _db.Categories.FirstOrDefault(b => b.categoryName.ToLower() == cat.categoryName.ToLower());
                if (i == null)
                {
                    _db.Categories.Add(cat);
                    _db.SaveChanges();

                    if (images != null)
                    {
                        foreach (var image in images)
                        {
                            var filePath  = Server.MapPath(ConfigurationManager.AppSettings["CategoryImagesPath"]);
                            var directory = new DirectoryInfo(filePath);
                            if (directory.Exists == false)
                            {
                                directory.Create();
                            }
                            string itemImgName = Guid.NewGuid() + image.FileName;
                            image.SaveAs(filePath + itemImgName);

                            CategoryImage img = new CategoryImage();
                            img.categoryId = cat.categoryId;
                            img.address    = itemImgName;
                            _db.CategoryImages.Add(img);
                            _db.SaveChanges();
                        }
                        TempData["AddCategoryMessage"] = "Category Added Successfully !";
                    }
                }
            }
            return(View());
        }
            public void Bind(ICategory model)
            {
                CellContentRootView?.SetBackgroundColor(ColorConstants.BackroundCell, 4);

                if (CellContentRootView != null)
                {
                    CellContentRootView.Tag    = model;
                    CellContentRootView.Click -= CellContentRootView_Click;
                    CellContentRootView.Click += CellContentRootView_Click;
                }

                if (CategoryText != null)
                {
                    CategoryText.Text = model.Name.ToUpperInvariant();
                    CategoryText.SetTextColor(ColorConstants.WhiteColor);
                    CategoryText.SetBackgroundColor(ColorConstants.SelectorHome, 4);
                    CategoryText.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size12);
                }

                if (CategoryImage != null)
                {
                    CategoryImage.SetImageFromResource(model.Image);
                    CategoryImage.SetBackgroundColor(ColorConstants.TransparentColor, 4);
                }
            }
Exemplo n.º 5
0
        public void SetCategoryImage(CategoryImage image)
        {
            MemoryStream targetMemoryStream;
            Stream       sourceStream = image.ImageStream;

            var imageCat = new byte[image.Size];

            using (targetMemoryStream = new MemoryStream(imageCat))
            {
                const int bufferLen = 4096;
                byte[]    buffer1   = new byte[bufferLen];
                int       count;
                while ((count = sourceStream.Read(buffer1, 0, bufferLen)) > 0)
                {
                    targetMemoryStream.Write(buffer1, 0, count);
                }
                targetMemoryStream.Close();
                sourceStream.Close();
            }

            using (var db = new Northwind())
            {
                var cat = db.Categories.FirstOrDefault(c => c.CategoryID == image.CategoryId);
                if (cat == null)
                {
                    throw new FaultException <CategoryNotFound>(new CategoryNotFound {
                        CategoryId = image.CategoryId
                    });
                }

                cat.Picture = imageCat;

                db.SaveChanges();
            }
        }
        public IActionResult UpdateGalleryCategory(CategoryImageUploadViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["GeneralError"] = Messages.RequiredInput;
                return(View(model));
            }

            CategoryImage categoryImage = new CategoryImage
            {
                Name = model.Name,
                Id   = model.Id
            };

            var result = _categoryImageService.Update(categoryImage);

            if (result.Success)
            {
                ViewData["GeneralSuccess"] = result.Message;
                return(RedirectToAction("ListGalleryCategory", "ManagementPanel"));
            }

            ViewData["GeneralError"] = Messages.GeneralError;
            return(View(model));
        }
Exemplo n.º 7
0
        public HttpResponseMessage Put(int id, [FromBody] CategoryImage category)
        {
            try
            {
                using (Store2DoorEntities entities = new Store2DoorEntities())
                {
                    var entity = entities.CategoryImages.FirstOrDefault(e => e.category_id == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Category image with id " + id.ToString() + " not found to edit"));
                    }
                    else
                    {
                        entity.images = category.images;



                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.OK, ex));
            }
        }
        public IActionResult Put(string id, [FromBody] CategoryImage image)
        {
            CategoryImageBO categoryImageBO;
            ObjectResult    response;

            try
            {
                _log.LogInformation($"Starting Put( {id}, '{JsonConvert.SerializeObject(image, Formatting.None)}')");

                categoryImageBO = new CategoryImageBO(_loggerFactory, _config);

                image.BlobFile.ID = id;
                image             = categoryImageBO.Update(image);

                response = Ok(image);

                _log.LogInformation($"Finishing Put( {id} )");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
Exemplo n.º 9
0
 protected CategoryBase(Guid id, string name, string description, int order, CategoryImage imageCategory)
 {
     Id            = id;
     Name          = name;
     Description   = description;
     Order         = order;
     CategoryImage = imageCategory;
     IsActive      = true;
 }
Exemplo n.º 10
0
        public CategoryImage Update(CategoryImage image)
        {
            CategoryBO categoryBO;
            BlobFileBO blobFileBO;
            Category   category;

            try
            {
                categoryBO = new CategoryBO(_loggerFactory, _config);
                blobFileBO = new BlobFileBO(_loggerFactory, _config);

                if (string.IsNullOrEmpty(image.BlobFile?.ID))
                {
                    throw new Exception("ID vazio, avalie a utilização do POST");
                }
                else
                {
                    category = categoryBO.Get(image.CategoryID);

                    if (category != null)
                    {
                        image.BlobFile = blobFileBO.Update(image.BlobFile);

                        switch (image.Destination)
                        {
                        case CategoryImage.CategoryImageDestination.Desktop:
                            category.DesktopSpotlightImageID = image.BlobFile.ID;
                            break;

                        case CategoryImage.CategoryImageDestination.Mobile:
                            category.MobileSpotlightImageID = image.BlobFile.ID;
                            break;

                        default:
                            break;
                        }

                        categoryBO.Update(category);
                    }
                    else
                    {
                        throw new Exception("Produto não encontrado");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(image);
        }
        void ReleaseDesignerOutlets()
        {
            if (CategoryImage != null)
            {
                CategoryImage.Dispose();
                CategoryImage = null;
            }

            if (lblName != null)
            {
                lblName.Dispose();
                lblName = null;
            }
        }
Exemplo n.º 12
0
        public async Task <int> AddImageToCategoryAsync(string imageUrl, string categoryName)
        {
            var result = await this.cloudinaryImageService.UploadCategoryImageToCloudinaryAsync(imageUrl, categoryName);

            var image = new CategoryImage
            {
                ImageUrl = result.ImageUrl,
                PublicId = result.PublicId,
            };

            await this.imageRepository.AddAsync(image);

            await this.imageRepository.SaveChangesAsync();

            return(image.Id);
        }
Exemplo n.º 13
0
        private static void SeedCategoryImage(CatalogContext context, Guid categoryId, Guid mediaId)
        {
            if (!context.CategoryImages.Any(x => x.CategoryId == categoryId))
            {
                var categoryImage = new CategoryImage
                {
                    CategoryId = categoryId,
                    MediaId    = mediaId,
                    Order      = 0
                };

                context.CategoryImages.Add(categoryImage.FillCommonProperties());

                context.SaveChanges();
            }
        }
        public Task <CreateCategoryCommandResponse> Handle(CreateCategoryCommand command)
        {
            _categoryDomainService.CheckCategoryName(command.Name);
            var parentCategory = _repository.Find(command.ParentCategory);

            if (parentCategory == null)
            {
                throw new DomainException("دسته بندی پدر  یافت نشد");
            }
            var category = new Category(command.Id, command.Name, command.Description,
                                        parentCategory.SubCategories.Count, CategoryImage.CreateNullImage())
            {
                SubCategories = new List <Category>()
            };

            parentCategory.SubCategories.Add(category);
            return(Task.FromResult(new CreateCategoryCommandResponse()));
        }
Exemplo n.º 15
0
 public HttpResponseMessage Post([FromBody] CategoryImage category)
 {
     try
     {
         using (Store2DoorEntities entities = new Store2DoorEntities())
         {
             entities.CategoryImages.Add(category);
             entities.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, category);
             message.Headers.Location = new Uri(Request.RequestUri + category.category_id.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Exemplo n.º 16
0
        void ReleaseDesignerOutlets()
        {
            if (CategoryImage != null)
            {
                CategoryImage.Dispose();
                CategoryImage = null;
            }

            if (CategoryName != null)
            {
                CategoryName.Dispose();
                CategoryName = null;
            }

            if (frameView != null)
            {
                frameView.Dispose();
                frameView = null;
            }
        }
Exemplo n.º 17
0
        public CategoryImage GetCategoryImage(CategoryImage image)
        {
            using (var db = new Northwind())
            {
                var id  = image.CategoryId;
                var cat = db.Categories.FirstOrDefault(c => c.CategoryID == id);
                if (cat == null)
                {
                    throw new FaultException <CategoryNotFound>(new CategoryNotFound {
                        CategoryId = id
                    });
                }

                var imageStream = new MemoryStream(cat.Picture);
                return(new CategoryImage
                {
                    CategoryId = id,
                    ImageStream = imageStream,
                    Size = cat.Picture.Length
                });
            }
        }
Exemplo n.º 18
0
        public async Task <CategoryServiceModel> CreateAsync(CreateCategoryServiceModel model)
        {
            var category = new Category
            {
                Parentid = model.ParentId,
                IsLeaf   = true
            };

            var parentCategory = await this.context.Categories.FirstOrDefaultAsync(x => x.Id == model.ParentId && x.IsActive);

            category.Level = parentCategory.Level + 1;

            this.context.Categories.Add(category.FillCommonProperties());

            var categoryTranslation = new CategoryTranslation
            {
                CategoryId = category.Id,
                Name       = model.Name,
                Language   = model.Language
            };

            this.context.CategoryTranslations.Add(categoryTranslation.FillCommonProperties());

            foreach (var file in model.Files.OrEmptyIfNull())
            {
                var categoryImage = new CategoryImage
                {
                    CategoryId = category.Id,
                    MediaId    = file,
                };

                this.context.CategoryImages.Add(categoryImage.FillCommonProperties());
            }

            await this.context.SaveChangesAsync();

            return(await this.GetAsync(new GetCategoryServiceModel { Id = category.Id, Language = model.Language, OrganisationId = model.OrganisationId, Username = model.Username }));
        }
Exemplo n.º 19
0
        public CategoryImage GetCategoryImage(CategoryImage image)
        {
            using (var db = new Northwind())
            {
                var id  = image.CategoryId;
                var cat = db.Categories.FirstOrDefault(c => c.CategoryID == id);
                if (cat == null)
                {
                    throw new FaultException <CategoryFault>(new CategoryFault()
                    {
                        CategoryId = id, Message = "Категория с заданным Id не найдена"
                    });
                }

                var imageStream = new MemoryStream(cat.Picture);
                return(new CategoryImage
                {
                    CategoryId = id,
                    ImageStream = imageStream,
                    Size = cat.Picture.Length
                });
            }
        }
Exemplo n.º 20
0
        private void btnSet_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tbPath.Text))
            {
                MessageBox.Show(@"Не выбрано изображение.");
                return;
            }

            using (var service = _factory.CreateChannel())
            {
                using (var stream = new FileStream(tbPath.Text, FileMode.Open, FileAccess.Read))
                {
                    var image = new CategoryImage {
                        CategoryId = (int)cbCategories.SelectedValue, Size = (int)stream.Length, ImageStream = stream
                    };
                    try
                    {
                        service.SetCategoryImage(image);
                    }
                    catch
                    {
                        MessageBox.Show(@"Изображение не отправлено.");
                        if (service.State == CommunicationState.Faulted)
                        {
                            service.Abort();
                        }
                        else
                        {
                            service.Close();
                        }
                        return;
                    }
                }
            }

            MessageBox.Show(@"Изображение отправлено");
        }
Exemplo n.º 21
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            Stream stream = new MemoryStream();
            int    id     = (int)cbCategories.SelectedValue;
            var    img    = new CategoryImage {
                ImageStream = stream, CategoryId = id
            };

            using (var service = _factory.CreateChannel())
            {
                try
                {
                    img = service.GetCategoryImage(img);
                }
                catch
                {
                    if (service.State == CommunicationState.Faulted)
                    {
                        service.Abort();
                    }
                    else
                    {
                        service.Close();
                    }
                }
            }

            #region Сохранение в файл

            /*FileStream targetStream = null;
             * Stream sourceStream = stream;
             *
             * string filePath = @"D:\Temp\getFile.jpg";
             *
             * using (targetStream = new FileStream(filePath, FileMode.Create,
             *      FileAccess.Write, FileShare.None))
             * {
             *      const int bufferLen = 4096;
             *      byte[] buffer1 = new byte[bufferLen];
             *      int count = 0;
             *      while ((count = sourceStream.Read(buffer1, 0, bufferLen)) > 0)
             *      {
             *              targetStream.Write(buffer1, 0, count);
             *      }
             *      targetStream.Close();
             *      sourceStream.Close();
             * }*/
            #endregion

            MemoryStream targetMemoryStream;
            var          imageCat = new byte[img.Size];

            using (targetMemoryStream = new MemoryStream(imageCat))
            {
                const int bufferLen = 4096;
                byte[]    buffer1   = new byte[bufferLen];
                int       count;
                while ((count = img.ImageStream.Read(buffer1, 0, bufferLen)) > 0)
                {
                    targetMemoryStream.Write(buffer1, 0, count);
                }

                try
                {
                    pbCategoryImage.Image = Image.FromStream(targetMemoryStream);
                }
                catch
                {
                    MessageBox.Show(@"Ошибка при показе изображения.");
                    Clear();
                }
                targetMemoryStream.Close();
                img.ImageStream.Close();
            }
        }
Exemplo n.º 22
0
            public void Bind(IOrderContent model)
            {
                CellContentRootView?.SetBackgroundColor(ColorConstants.BackroundCell, 5);
                CategoryImage?.SetImageFromUrl(model.ImagePath);

                if (!RemoveOrderImage.IsNull())
                {
                    RemoveOrderImage?.SetImageFromResource(DrawableConstants.OrderRemoveIcon);

                    RemoveOrderImage.Tag = model;

                    RemoveOrderImage.Click -= RemoveOrderImage_Click;
                    RemoveOrderImage.Click += RemoveOrderImage_Click;
                }

                if (!ItemNameText.IsNull())
                {
                    ItemNameText.Text = model.OrderName;
                    ItemNameText?.SetTextColor(ColorConstants.WhiteColor);
                    ItemNameText.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (!PriceText.IsNull())
                {
                    PriceText.Text = "€" + model.Price * Convert.ToInt32(model.Quantity);
                    PriceText?.SetTextColor(ColorConstants.SelectorHome);
                    PriceText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (!MinusText.IsNull())
                {
                    MinusText?.SetTextColor(ColorConstants.WhiteColor);
                    MinusText?.SetFont(FontsConstant.OpenSansRegular, FontsConstant.Size20);
                    MinusText?.SetBackgroundColor(ColorConstants.SelectorHome, type: RadiusType.Aspect);
                    MinusText?.SetSelectedColor(ColorConstants.SelectorHome.SelectorTransparence(ColorConstants.Procent50));
                    MinusText.Text = "-";
                    MinusText.Tag  = new { Model = model };

                    MinusText.Click -= MinusText_Click;
                    MinusText.Click += MinusText_Click;
                }

                if (!QuantityText.IsNull())
                {
                    QuantityText.Text = model.Quantity;
                    QuantityText?.SetTextColor(ColorConstants.WhiteColor);
                    QuantityText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (PlusText.IsNull())
                {
                    return;
                }
                PlusText?.SetTextColor(ColorConstants.WhiteColor);
                PlusText?.SetFont(FontsConstant.OpenSansRegular, FontsConstant.Size20);
                PlusText.Text = "+";
                PlusText?.SetBackgroundColor(ColorConstants.SelectorHome, type: RadiusType.Aspect);
                PlusText?.SetSelectedColor(ColorConstants.SelectorHome.SelectorTransparence(ColorConstants.Procent50));

                PlusText.Tag = new { Model = model };

                PlusText.Click -= PlusText_Click;
                PlusText.Click += PlusText_Click;
            }
 public IResult Add(CategoryImage categoryImage)
 {
     _categoryImageDal.Add(categoryImage);
     return(new SuccessResult(Messages.CategoryImageAdded));
 }
Exemplo n.º 24
0
 public CategoryRoot(Guid id, string name, string description, int order, CategoryImage imageCategory) : base(id, name, description, order, imageCategory)
 {
 }
 public IResult Update(CategoryImage categoryImage)
 {
     _categoryImageDal.Update(categoryImage);
     return(new SuccessResult(Messages.CategoryImageUpdated));
 }
Exemplo n.º 26
0
        public async Task <CategoryServiceModel> UpdateAsync(UpdateCategoryServiceModel model)
        {
            var category = await this.context.Categories.FirstOrDefaultAsync(x => x.Id == model.Id && x.IsActive);

            if (category == null)
            {
                throw new CustomException(this.productLocalizer.GetString("CategoryNotFound"), (int)HttpStatusCode.NotFound);
            }

            var parentCategory = await this.context.Categories.FirstOrDefaultAsync(x => x.Id == model.ParentId && x.IsActive);

            if (parentCategory == null)
            {
                throw new CustomException(this.productLocalizer.GetString("ParentCategoryNotFound"), (int)HttpStatusCode.NotFound);
            }

            category.Parentid = model.ParentId;
            category.Level    = parentCategory.Level + 1;
            category.IsLeaf   = !await this.context.Categories.AnyAsync(x => x.Parentid == category.Id && x.IsActive);

            category.LastModifiedDate = DateTime.UtcNow;

            var categoryTranslation = await this.context.CategoryTranslations.FirstOrDefaultAsync(x => x.CategoryId == model.Id && x.Language == model.Language && x.IsActive);

            if (categoryTranslation != null)
            {
                categoryTranslation.Name = model.Name;
            }
            else
            {
                var newCategoryTranslation = new CategoryTranslation
                {
                    CategoryId = category.Id,
                    Name       = model.Name
                };

                this.context.CategoryTranslations.Add(newCategoryTranslation.FillCommonProperties());
            }

            categoryTranslation.LastModifiedDate = DateTime.UtcNow;

            var categoryImages = this.context.CategoryImages.Where(x => x.CategoryId == model.Id);

            foreach (var categoryImage in categoryImages)
            {
                this.context.CategoryImages.Remove(categoryImage);
            }

            if (model.Files != null)
            {
                foreach (var file in model.Files)
                {
                    var categoryImage = new CategoryImage
                    {
                        CategoryId = model.Id.Value,
                        MediaId    = file
                    };

                    this.context.CategoryImages.Add(categoryImage.FillCommonProperties());
                }
            }

            await this.context.SaveChangesAsync();

            return(await this.GetAsync(new GetCategoryServiceModel { Id = category.Id, Language = model.Language, OrganisationId = model.OrganisationId, Username = model.Username }));
        }