public async Task <IActionResult> Create(ServiceAddDto serviceAddDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\service");

                    serviceAddDto.ImageUrl = imgName;
                }
                else
                {
                    serviceAddDto.ImageUrl = "no-photo.png";
                }
                await _serviceService.InsertAsync(new Service
                {
                    ImageUrl = serviceAddDto.ImageUrl,
                    Text     = serviceAddDto.Text,
                    Title    = serviceAddDto.Title
                });

                return(RedirectToAction("Index"));
            }
            return(View(serviceAddDto));
        }
        public async Task <IActionResult> Create(PortofolioAddDto portofolioAddDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    var imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\portofolio");

                    portofolioAddDto.ImageUrl = imgName;
                }
                else
                {
                    portofolioAddDto.ImageUrl = "no-image.png";
                }

                await _portofolioService.InsertAsync(new Portofolio
                {
                    SubCategoryId = portofolioAddDto.SubCategoryId,
                    Text          = portofolioAddDto.Text,
                    Title         = portofolioAddDto.Title,
                    ImageUrl      = portofolioAddDto.ImageUrl
                });

                return(RedirectToAction("Index"));
            }

            portofolioAddDto.CategoryList = new SelectList(await _categoryService.GetListAsync(), "Id", "Name");
            return(View(portofolioAddDto));
        }
        public async Task <IActionResult> Edit(ServiceGeneralDto serviceGeneralDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\service");

                    serviceGeneralDto.ImageUrl = imgName;
                }
                else
                {
                    var editedService = await _serviceService.GetByIdAsync(serviceGeneralDto.Id);

                    serviceGeneralDto.ImageUrl = editedService.ImageUrl;
                }

                await _serviceService.UpdateAsync(new Service
                {
                    ImageUrl = serviceGeneralDto.ImageUrl,
                    Id       = serviceGeneralDto.Id,
                    Text     = serviceGeneralDto.Text,
                    Title    = serviceGeneralDto.Title
                });

                return(RedirectToAction("Index"));
            }
            return(View(serviceGeneralDto));
        }
Exemple #4
0
        public async Task <IActionResult> Edit(TestimionalGeneralDto testimionalGeneralDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\testimonial");

                    testimionalGeneralDto.ImageUrl = imgName;
                }
                else
                {
                    var editedTestimional = await _testimionalService.GetByIdAsync(testimionalGeneralDto.Id);

                    testimionalGeneralDto.ImageUrl = editedTestimional.ImageUrl;
                }
                await _testimionalService.UpdateAsync(new Testimonial
                {
                    Id       = testimionalGeneralDto.Id,
                    ImageUrl = testimionalGeneralDto.ImageUrl,
                    IsDraft  = testimionalGeneralDto.IsDraft,
                    Name     = testimionalGeneralDto.Name,
                    Text     = testimionalGeneralDto.Text,
                    Title    = testimionalGeneralDto.Title
                });

                return(RedirectToAction("Index"));
            }
            return(View(testimionalGeneralDto));
        }
Exemple #5
0
        public async Task <IActionResult> Create(BlogAddDto blogAddDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\blog");

                    blogAddDto.ImageUrl = imgName;
                }
                else
                {
                    blogAddDto.ImageUrl = "no-photo.png";
                }

                await _blogService.InsertAsync(new Blog
                {
                    AppUserId     = 1,
                    SubCategoryId = blogAddDto.SubCategoryId,
                    ImageUrl      = blogAddDto.ImageUrl,
                    Text          = blogAddDto.Text,
                    Title         = blogAddDto.Title,
                    CreatedDate   = DateTime.Now
                });

                return(RedirectToAction("Index"));
            }

            blogAddDto.CategoryList = new SelectList(await _categoryService.GetListAsync(), "Id", "Name");
            return(View(blogAddDto));
        }
Exemple #6
0
        public async Task <IActionResult> PhotoUpload(IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment, ProfileGeneralDto profileGeneralDto)
        {
            if (ModelState.IsValid)
            {
                var activeUser = await _appUserService.GetByIdAsync(profileGeneralDto.Id);

                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\profile");

                    profileGeneralDto.ProfileImageUrl = imgName;
                    activeUser.ProfileImageUrl        = profileGeneralDto.ProfileImageUrl;
                }
                //else
                //{
                //    profileGeneralDto.ProfileImageUrl = activeUser.ProfileImageUrl;
                //}
                //activeUser.ProfileImageUrl = profileGeneralDto.ProfileImageUrl;

                await _appUserService.UpdateAsync(activeUser);

                return(RedirectToAction("Index"));
            }
            return(null);
        }
Exemple #7
0
        public async Task <IActionResult> Edit(BlogGeneralDto blogGeneralDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                var editedBlog = await _blogService.GetByIdAsync(blogGeneralDto.Id);

                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\blog");

                    blogGeneralDto.ImageUrl = imgName;
                }
                else
                {
                    blogGeneralDto.ImageUrl = editedBlog.ImageUrl;
                }

                await _blogService.UpdateAsync(new Blog
                {
                    Id            = blogGeneralDto.Id,
                    ImageUrl      = blogGeneralDto.ImageUrl,
                    AppUserId     = 1,
                    SubCategoryId = blogGeneralDto.SubCategoryId,
                    Text          = blogGeneralDto.Text,
                    Title         = blogGeneralDto.Title,
                    CreatedDate   = editedBlog.CreatedDate,
                    ModifiedDate  = DateTime.Now
                });

                return(RedirectToAction("Index"));
            }
            var activeCategory = await _categoryService.GetCategoryBySubCatIdAsync(blogGeneralDto.SubCategoryId);

            blogGeneralDto.CategoryList    = new SelectList(await _categoryService.GetListAsync(), "Id", "Name", activeCategory.Id);
            blogGeneralDto.SubCategoryList = new SelectList(await _subCategoryService.GetListByFilterAsync(x => x.CategoryId == activeCategory.Id), "Id", "Name", blogGeneralDto.SubCategoryId);
            return(View(blogGeneralDto));
        }
        public async Task <IActionResult> Edit(PortofolioGeneralDto portofolioGeneralDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null /*&& (imgFile.ContentType == "image/jpg" || imgFile.ContentType == "image/png" || imgFile.ContentType == "image/jpeg")*/)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\portofolio");

                    portofolioGeneralDto.ImageUrl = imgName;
                }
                else
                {
                    var updatedPortofolioForImageUrl = await _portofolioService.GetByIdAsync(portofolioGeneralDto.Id);

                    portofolioGeneralDto.ImageUrl = updatedPortofolioForImageUrl.ImageUrl;
                }


                await _portofolioService.UpdateAsync(new Portofolio
                {
                    Id            = portofolioGeneralDto.Id,
                    ImageUrl      = portofolioGeneralDto.ImageUrl,
                    SubCategoryId = portofolioGeneralDto.SubCategoryId,
                    Text          = portofolioGeneralDto.Text,
                    Title         = portofolioGeneralDto.Title
                });

                return(RedirectToAction("Index"));
            }
            var activeCategory = await _categoryService.GetCategoryBySubCatIdAsync(portofolioGeneralDto.SubCategoryId);

            portofolioGeneralDto.CategoryList    = new SelectList(await _categoryService.GetListAsync(), "Id", "Name", activeCategory.Id);
            portofolioGeneralDto.SubCategoryList = new SelectList(await _subCategoryService.GetListByFilterAsync(x => x.CategoryId == activeCategory.Id), "Id", "Name", portofolioGeneralDto.SubCategoryId);

            return(View(portofolioGeneralDto));
        }
Exemple #9
0
        public async Task <IActionResult> Create(TestimionalAddDto testimionalAddDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    string imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\testimonial");

                    testimionalAddDto.ImageUrl = imgName;
                }

                await _testimionalService.InsertAsync(new Testimonial
                {
                    IsDraft  = testimionalAddDto.IsDraft,
                    Name     = testimionalAddDto.Name,
                    Text     = testimionalAddDto.Text,
                    Title    = testimionalAddDto.Title,
                    ImageUrl = testimionalAddDto.ImageUrl
                });

                return(RedirectToAction("Index"));
            }
            return(View(testimionalAddDto));
        }