public async Task <ActionResult <Bio> > Update(int id, [FromForm] BioUpdateDto bioUpdateDto)
        {
            if (id != bioUpdateDto.Id)
            {
                return(BadRequest());
            }
            Bio dbBio = _context.Bios.FirstOrDefault(p => p.Id == id);

            if (dbBio == null)
            {
                return(NotFound());
            }
            dbBio.Phone    = bioUpdateDto.Phone;
            dbBio.Email    = bioUpdateDto.Email;
            dbBio.Facebook = bioUpdateDto.Facebook;
            dbBio.Address  = bioUpdateDto.Address;

            string folderName = Path.Combine("images", "logo");

            if (bioUpdateDto.Logo != null)
            {
                ImageExtension.DeleteImage(_env.WebRootPath, folderName, dbBio.LogoUrl);
                string fileName = await bioUpdateDto.Logo.SaveImg(_env.WebRootPath, folderName);

                dbBio.LogoUrl = fileName;
            }
            await _context.SaveChangesAsync();

            return(Ok(dbBio));
        }
        public async Task <ActionResult <About> > Update(int id, [FromForm] AboutUpdateDto aboutUpdateDto)
        {
            if (id != aboutUpdateDto.Id)
            {
                return(BadRequest());
            }
            About dbAbout = _context.Abouts.FirstOrDefault(p => p.Id == id);

            if (dbAbout == null)
            {
                return(NotFound());
            }
            dbAbout.Title       = aboutUpdateDto.Title;
            dbAbout.Description = aboutUpdateDto.Description;

            string folderName = Path.Combine("images", "about");

            if (aboutUpdateDto.Photo != null)
            {
                ImageExtension.DeleteImage(_env.WebRootPath, folderName, dbAbout.PhotoUrl);
                string fileName = await aboutUpdateDto.Photo.SaveImg(_env.WebRootPath, folderName);

                dbAbout.PhotoUrl = fileName;
            }
            await _context.SaveChangesAsync();

            return(Ok());
        }
Beispiel #3
0
        public async Task <Doctor> UpdateDoctorAsync(Doctor doctor, string webRoot)
        {
            var dbDoctor = await _context.Doctors.FirstOrDefaultAsync(x => x.Id == doctor.Id);

            if (dbDoctor == null)
            {
                return(dbDoctor);
            }

            string folderName = Path.Combine("images", "doctors");

            if (doctor.Photo != null)
            {
                ImageExtension.DeleteImage(webRoot, folderName, dbDoctor.PhotoUrl);
                string fileName = await doctor.Photo.SaveImg(webRoot, folderName);

                dbDoctor.PhotoUrl = fileName;
            }

            dbDoctor.Name         = doctor.Name;
            dbDoctor.Description  = doctor.Description;
            dbDoctor.Facebook     = doctor.Facebook;
            dbDoctor.Profession   = doctor.Profession;
            dbDoctor.DepartmentId = doctor.DepartmentId;
            await _context.SaveChangesAsync();

            return(dbDoctor);
        }
Beispiel #4
0
 public IActionResult Delete(int id, Product product)
 {
     try
     {
         var item         = procuctDb.Products.Find(id);
         var itemPictures = procuctDb.Pictures.Where(x => x.ProductID == id).ToList();
         var properies    = procuctDb.Properties.Where(x => x.ProductId == id).ToList();
         procuctDb.Properties.RemoveRange(properies);
         foreach (var itemPicture in itemPictures)
         {
             ImageExtension.DeleteImage(itemPicture.PhotoUrl, hostEnvironment);
         }
         procuctDb.Pictures.RemoveRange(itemPictures);
         procuctDb.Products.Remove(item);
         procuctDb.SaveChanges();
         DeletedProduct deleted = new DeletedProduct
         {
             DeletedDate = DateTime.Today,
             Name        = item.Name,
             DeletedId   = item.Id
         };
         procuctDb.DeletedProducts.Add(deleted);
         procuctDb.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(RedirectToAction(nameof(Delete), id));
     }
 }
        public async Task <Blog> UpdateBlogAsync(Blog blog, string webRoot)
        {
            var dbBlog = await _context.Blogs.FirstOrDefaultAsync(b => b.Id == blog.Id);

            if (dbBlog == null)
            {
                return(dbBlog);
            }
            string folderName = Path.Combine("images", "blog");

            if (blog.Photo != null)
            {
                ImageExtension.DeleteImage(webRoot, folderName, dbBlog.PhotoUrl);
                string fileName = await blog.Photo.SaveImg(webRoot, folderName);

                dbBlog.PhotoUrl = fileName;
            }

            dbBlog.Title       = blog.Title;
            dbBlog.Description = blog.Description;
            dbBlog.Topic       = blog.Topic;
            await _context.SaveChangesAsync();

            return(dbBlog);
        }
        public async Task <Product> UpdateProductAsync(Product product, string webRoot)
        {
            var dbProduct = await _context.Products.FirstOrDefaultAsync(x => x.Id == product.Id);

            if (dbProduct == null)
            {
                return(dbProduct);
            }

            string folderName = Path.Combine("images", "shop");

            if (product.Photo != null)
            {
                ImageExtension.DeleteImage(webRoot, folderName, dbProduct.PictureUrl);
                string fileName = await product.Photo.SaveImg(webRoot, folderName);

                dbProduct.PictureUrl = fileName;
            }
            dbProduct.Name           = product.Name;
            dbProduct.Price          = product.Price;
            dbProduct.Description    = product.Description;
            dbProduct.ProductBrandId = product.ProductBrandId;
            dbProduct.ProductTypeId  = product.ProductTypeId;
            await _context.SaveChangesAsync();

            return(dbProduct);
        }
Beispiel #7
0
        public bool RemoveImage(int id)
        {
            var picture = procuctDb.Pictures.Find(id);

            if (picture != null)
            {
                procuctDb.Pictures.Remove(picture);
                ImageExtension.DeleteImage(picture.PhotoUrl, hostEnvironment);
                procuctDb.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #8
0
        public string EditImage(int id, IFormFile image)
        {
            var picture = procuctDb.Pictures.Find(id);

            if (picture != null)
            {
                var file = picture.PhotoUrl;
                picture.PhotoUrl = image.CreateImage(hostEnvironment);
                if (file != picture.PhotoUrl)
                {
                    ImageExtension.DeleteImage(file, hostEnvironment);
                }
                procuctDb.SaveChanges();
                return(picture.PhotoUrl);
            }
            return(null);
        }
        public async Task <Product> DeleteProductAsync(int id, string webRoot)
        {
            var dbProduct = await _context.Products.FirstOrDefaultAsync(x => x.Id == id);

            if (dbProduct == null)
            {
                return(dbProduct);
            }

            string folderName = Path.Combine("images", "shop");

            _context.Products.Remove(dbProduct);
            ImageExtension.DeleteImage(webRoot, folderName, dbProduct.PictureUrl);
            await _context.SaveChangesAsync();

            return(dbProduct);
        }
Beispiel #10
0
        public async Task <Doctor> DeleteDoctorAsync(int id, string webRoot)
        {
            var dbDoctor = await _context.Doctors.FirstOrDefaultAsync(x => x.Id == id);

            if (dbDoctor == null)
            {
                return(dbDoctor);
            }

            string folderName = Path.Combine("images", "doctors");

            _context.Doctors.Remove(dbDoctor);
            ImageExtension.DeleteImage(webRoot, folderName, dbDoctor.PhotoUrl);

            await _context.SaveChangesAsync();

            return(dbDoctor);
        }
        public async Task <Blog> DeleteBlogAsync(int id, string webRoot)
        {
            var dbBlog = await _context.Blogs.FirstOrDefaultAsync(b => b.Id == id);

            if (dbBlog == null)
            {
                return(dbBlog);
            }

            string folderName = Path.Combine("images", "blog");

            _context.Blogs.Remove(dbBlog);
            ImageExtension.DeleteImage(webRoot, folderName, dbBlog.PhotoUrl);

            await _context.SaveChangesAsync();

            return(dbBlog);
        }