Пример #1
0
        public async Task <IActionResult> Create(int ID, string Title, string Description, IFormFile CoverPhoto)
        {
            var project = new Project
            {
                ID          = ID,
                Title       = Title,
                Description = Description,
                CoverPhoto  = "",
                EditedDate  = DateTime.Now,
            };

            if (!ModelState.IsValid)
            {
                return(View());
            }

            BlobsController blobsController = new BlobsController();

            if (!blobsController.UploadBlobFunction("Content-" + project.Title, CoverPhoto.OpenReadStream()))
            {
                ModelState.AddModelError(string.Empty, "The image file failed to upload.");
                return(View());
            }
            project.CoverPhoto = "Content-" + project.Title;

            project.EditedDate = DateTime.Now;
            _context.Add(project);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            if (HttpHelper.HttpContext.Session.GetString("currentUser") != null)
            {
                ViewBag.user = HttpHelper.HttpContext.Session.GetString("currentUser");
            }

            if (HttpHelper.HttpContext.Session.GetString("role") != null)
            {
                ViewBag.role = HttpHelper.HttpContext.Session.GetString("role");
            }


            var dish = await _context.Dish.FindAsync(id);

            string          imgRef = dish.ImgLink.Replace("https://westdelistorage.blob.core.windows.net/image-blob-container/", "");
            BlobsController bc     = new BlobsController();

            bc.DeleteBlob(imgRef);

            _context.Dish.Remove(dish);
            await _context.SaveChangesAsync();


            return(RedirectToAction(nameof(Index)));
        }
Пример #3
0
 public BlobsControllerTests()
 {
     _controller = new BlobsController(
         new BlobServiceOptions(),
         new LoggerFactoryMock(),
         new StorageServiceMock(),
         new BlobStoreMock(),
         new BlobMetaDataStoreMock(),
         new ContainerStoreMock());
 }
Пример #4
0
        public async Task <IActionResult> Edit(int id, int ID, string Title, string Description, IFormFile CoverPhoto)
        {
            if (id != ID)
            {
                return(NotFound());
            }

            var project = new Project
            {
                ID         = ID,
                Title      = Title,
                EditedDate = DateTime.Now,
            };

            if (!ModelState.IsValid)
            {
                return(View(project));
            }

            if (CoverPhoto != null)
            {
                BlobsController blobsController = new BlobsController();
                if (!blobsController.UploadBlobFunction("Content-" + project.Title, CoverPhoto.OpenReadStream()))
                {
                    ModelState.AddModelError(string.Empty, "The image file failed to upload.");
                    return(View());
                }
                project.CoverPhoto = "Content-" + project.Title;
            }

            try
            {
                _context.Update(project);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectExists(project.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
        public async Task <IActionResult> Post([Bind("ID,DishName,Price,PrepTime,Category,Description")] Dish dish, List <IFormFile> files)
        {
            long sizes = files.Sum(f => f.Length);

            var filepath = Path.GetTempFileName();

            foreach (var FormFile in files)
            {
                if (!FormFile.ContentType.ToLower().StartsWith("image"))
                {
                    return(BadRequest("The " + Path.GetFileName(filepath) +
                                      " is not a jpg file! Please re-upload a correct file!"));
                }
                else if (FormFile.Length <= 0)
                {
                    return(BadRequest("The " + Path.GetFileName(filepath) +
                                      " is EMPTY! Please re-upload non empty file!"));
                }
                else if (FormFile.Length > 1048576) //>1MB
                {
                    return(BadRequest("The " + Path.GetFileName(filepath) +
                                      " is more than 1MB! Please re-upload a file less than 1MB!"));
                }
                else
                {
                    BlobsController bc = new BlobsController();
                    bc.UploadBlob(FormFile, Path.GetTempFileName());

                    if (ModelState.IsValid)
                    {
                        dish.ImgLink = "https://westdelistorage.blob.core.windows.net/image-blob-container/" + FormFile.FileName;
                        _context.Add(dish);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(dish));
                }
            }

            return(View(dish));
        }