Ejemplo n.º 1
0
        public async Task<IActionResult> AddLike(int id)
        {
            Product product = await _reminddb.Products.FirstOrDefaultAsync(h => h.Id == id);
            // var myuser = await _userManager.FindByNameAsync(User.Identity.Name);
            NewUser user = await GetCurrentUserAsync();
            if (user.Id == null || user == null)
            {
                return RedirectToAction(nameof(Index));
            }


            Like like = new Like()
            {
                LikeCount = 1,
                NewUserId = user.Id,
                ProductId = product.Id

            };

            await _reminddb.Likes.AddAsync(like);
            await _reminddb.SaveChangesAsync();


            return View();
        }
        public async Task <IActionResult> Create(AboutSlider slider)
        {
            if (slider.Photo != null)
            {
                if (!slider.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "You can chose only image format");
                    return(View());
                }

                if (!slider.Photo.CheckSize(2))
                {
                    ModelState.AddModelError("Photo", "You can chose only small 2 MB");
                    return(View());
                }


                string createdImage = await slider.Photo.CopyImage(_env.WebRootPath, "team");

                #region
                AboutSlider newslider = new AboutSlider()
                {
                    ImagePath = createdImage
                };
                #endregion



                await _remindb.AboutSliders.AddAsync(newslider);
            }

            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(Blog blog)
        {
            if (ModelState["Title"].ValidationState == ModelValidationState.Invalid ||
                ModelState["Photo"].ValidationState == ModelValidationState.Invalid)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (blog.Photo != null)
            {
                if (!blog.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "You can chose only image format");
                    return(View());
                }

                if (!blog.Photo.CheckSize(2))
                {
                    ModelState.AddModelError("Photo", "You can chose only small 2 MB");
                    return(View());
                }


                string createdImage = await blog.Photo.CopyImage(_env.WebRootPath, "blog");

                #region
                Blog newblog = new Blog()
                {
                    Title       = blog.Title,
                    Link        = blog.Link,
                    HeaderBig   = blog.HeaderBig,
                    HeaderSmall = blog.HeaderSmall,
                    CreatedDate = DateTime.Now
                };
                #endregion


                newblog.ImagePath = createdImage;

                // return Content($"{newproduct.Image}");
                await _remindb.Blogs.AddAsync(newblog);
            }

            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(Team createTeam)
        {
            if (ModelState["Name"].ValidationState == ModelValidationState.Invalid ||
                ModelState["Job"].ValidationState == ModelValidationState.Invalid ||
                ModelState["About"].ValidationState == ModelValidationState.Invalid)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (createTeam.Photo != null)
            {
                if (!createTeam.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "You can chose only image format");
                    return(View());
                }

                if (!createTeam.Photo.CheckSize(2))
                {
                    ModelState.AddModelError("Photo", "You can chose only small 2 MB");
                    return(View());
                }


                string createdImage = await createTeam.Photo.CopyImage(_env.WebRootPath, "team");

                #region
                Team newteam = new Team()
                {
                    Name  = createTeam.Name,
                    Job   = createTeam.Job,
                    About = createTeam.About
                };
                #endregion


                newteam.ImagePath = createdImage;

                // return Content($"{newproduct.Image}");
                await _remindb.Teams.AddAsync(newteam);
            }

            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(HomeSliderBig homeslider)
        {
            if (ModelState["Name"].ValidationState == ModelValidationState.Invalid ||
                ModelState["SubTitle"].ValidationState == ModelValidationState.Invalid ||
                ModelState["Link"].ValidationState == ModelValidationState.Invalid)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (homeslider.Photo != null)
            {
                if (!homeslider.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "You can chose only image format");
                    return(View());
                }

                if (!homeslider.Photo.CheckSize(2))
                {
                    ModelState.AddModelError("Photo", "You can chose only small 2 MB");
                    return(View());
                }


                string createdImage = await homeslider.Photo.CopyImage(_env.WebRootPath, "team");

                #region
                HomeSliderBig newhome = new HomeSliderBig()
                {
                    Title    = homeslider.Title,
                    SubTitle = homeslider.SubTitle,
                    Link     = homeslider.Link
                };
                #endregion


                newhome.ImgPath = createdImage;


                await _remindb.HomeSliderBigs.AddAsync(newhome);
            }

            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind(include: "")] ProductDashoardViewModel createdashVM)
        {
            try
            {
                if (ModelState["Name"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["Title"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["Description"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["Count"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["Price"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["DiscountProduct"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["ProductDedline"].ValidationState == ModelValidationState.Invalid ||
                    ModelState["PhotoList"].ValidationState == ModelValidationState.Invalid)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                if (createdashVM.PhotoList.Count != 0)
                {
                    if (createdashVM.DiscountProduct == 0)
                    {
                        createdashVM.ProductDedline = null;
                    }
                    ;

                    #region
                    product = new Product()
                    {
                        Name            = createdashVM.Name,
                        Title           = createdashVM.Title,
                        Description     = createdashVM.Description,
                        Price           = createdashVM.Price,
                        Count           = createdashVM.Count,
                        DiscountProduct = createdashVM.DiscountProduct,
                        ProductDedline  = createdashVM.ProductDedline,
                        CreatedDate     = DateTime.Now,
                        MostView        = createdashVM.MostView,
                        SellerCount     = 0,
                        Active          = null
                    };
                    #endregion
                    if (!_remindb.CategoryMarkas.Any(cm => cm.CategoryId == createdashVM.CategoryId && cm.MarkaId == createdashVM.MarkaId))
                    {
                        CategoryMarka categoryMarka = new CategoryMarka()
                        {
                            CategoryId = createdashVM.CategoryId,
                            MarkaId    = createdashVM.MarkaId,
                        };
                        await _remindb.CategoryMarkas.AddAsync(categoryMarka);

                        await _remindb.SaveChangesAsync();

                        product.CategoryMarkaId = categoryMarka.Id;
                    }
                    else
                    {
                        product.CategoryMarkaId = _remindb.CategoryMarkas.FirstOrDefault(cm => cm.CategoryId == createdashVM.CategoryId && cm.MarkaId == createdashVM.MarkaId).Id;
                    };
                    _remindb.Products.Add(product);
                    _remindb.SaveChanges();

                    foreach (var generateimage in createdashVM.PhotoList)
                    {
                        if (!generateimage.IsImage())
                        {
                            ModelState.AddModelError("Photo", "You can chose only image format");
                            return(View());
                        }
                        if (!generateimage.CheckSize(2))
                        {
                            ModelState.AddModelError("Photo", "You can chose only small 2 MB");
                            return(View());
                        }
                        string createdImage = await generateimage.CopyImage(_env.WebRootPath, "product");

                        Image image = new Image()
                        {
                            PathImage = createdImage,
                            ProductId = product.Id,
                            Active    = null,
                        };
                        await _remindb.Images.AddAsync(image);

                        await _remindb.SaveChangesAsync();
                    }
                    ;
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction("Index", "ProductGenerate"));
        }