private void SaveThumbnail(CreateBackgroundModel model, string thumbnailPath) { var sourceImage = new KalikoImage(model.File.OpenReadStream()); var fitScaling = new FitScaling(192, 108); var image = fitScaling.Scale(sourceImage); image.SavePng($"{_appEnvironment.WebRootPath}{thumbnailPath}"); }
private async Task SaveImageAsync(CreateBackgroundModel model, string imagePath) { var path = $"{_appEnvironment.WebRootPath}{imagePath}"; await using (var fileStream = new FileStream(path, FileMode.Create)) { await model.File.CopyToAsync(fileStream); } }
public async Task <ActionResult> Create_Background(CreateBackgroundModel model) { if (ModelState.IsValid) { var currentFileName = model.File; model.FileName = model.File.FileName; // Check if this creation include fileupload, which will require us to save the file model.File = currentFileName; if (model.File != null) { // upload the file var result = await new FileUploadController().FileUploadToApi <List <FileUploadModel> >(model.File); if (result.isSuccess) { var data = result.Data; var fileDocument = data[0]; fileDocument.CreatedBy = CurrentUser.UserId.Value; var resultUpload = await WepApiMethod.SendApiAsync <string>(HttpVerbs.Post, FileUploadApiUrl.FileUploadInfo, fileDocument); if (resultUpload.isSuccess) { model.File = null; model.FileUploadId = int.Parse(resultUpload.Data); var response = await WepApiMethod.SendApiAsync <string>(HttpVerbs.Post, $"eLearning/Certificate/Create_Background", model); if (response.isSuccess) { TempData["SuccessMessage"] = "Image background successfully added."; await LogActivity(Modules.Learning, "Create certificate background : " + model.Description); } } else { TempData["ErrorMessage"] = "Cannot upload file"; } } } return(RedirectToAction("Index", "Certificates", new { area = "eLearning" })); } TempData["ErrorMessage"] = "Cannot add background."; return(View(model)); }
//[HttpPost] //[ValidationActionFilter] public IHttpActionResult Post([FromBody] CreateBackgroundModel model) { var cert = new CourseCertificate { Name = model.Name, Description = model.Description, BackgroundImageFilename = model.FileName, FileUploadId = model.FileUploadId.Value, TypePageOrientation = model.TypePageOrientation }; db.CourseCertificates.Add(cert); db.SaveChanges(); return(Ok(cert.Id)); }
public IHttpActionResult Get(int id) { var bg = db.CourseCertificates.Where(u => u.Id == id).FirstOrDefault(); CreateBackgroundModel model = new CreateBackgroundModel { Id = bg.Id, Name = bg.Name, Description = bg.Description, FileUpload = bg.FileUpload, TypePageOrientation = bg.TypePageOrientation }; if (model != null) { return(Ok(model)); } return(NotFound()); }
//[HttpPost] //[ValidationActionFilter] public string Update_Background([FromBody] CreateBackgroundModel model) { if (model.Id != 0) { var cert = db.CourseCertificates.Where(x => x.Id == model.Id).FirstOrDefault(); if (cert != null) { cert.Name = model.Name; cert.Description = model.Description; cert.TypePageOrientation = model.TypePageOrientation; db.Entry(cert).State = EntityState.Modified; db.SaveChanges(); return(model.Description); } } return(""); }
public async Task <IActionResult> CreateBackground(CreateBackgroundModel model) { var board = _boards.GetEntity(model.BoardId); if (board == null) { return(RedirectToAction("Boards")); } var imagePath = $"/{ImageStorageFolder}/{model.File.FileName}"; await SaveImageAsync(model, imagePath); var thumbnailName = $"min.{model.File.FileName}"; var thumbnailPath = $"/{ThumbnailStorageFolder}/{thumbnailName}"; SaveThumbnail(model, thumbnailPath); var image = new Image { Name = model.File.FileName, ImageType = model.Type, Path = imagePath, Boards = new List <Board> { board } }; var thumbnail = new Thumbnail { Name = thumbnailName, Path = thumbnailPath, User = board.User, Image = image }; image.Thumbnail = thumbnail; _images.AddEntity(image); _images.Save(); return(RedirectToAction("Board", new { id = model.BoardId })); }
//[ValidateAntiForgeryToken] public async Task <ActionResult> Update_Background(CreateBackgroundModel model) { if (model.Description != null) { var response = await WepApiMethod.SendApiAsync <string>(HttpVerbs.Post, $"eLearning/Certificates/Update_Background", model); if (response.isSuccess) { await LogActivity(Modules.Learning, "Delete Background: " + response.Data); TempData["SuccessMessage"] = "Background Name " + response.Data + " successfully updated."; return(RedirectToAction("Index", "Certificates", new { area = "eLearning" })); } else { TempData["SuccessMessage"] = "Failed to delete certificate background."; return(RedirectToAction("Edit_Background", "Certificates", new { area = "eLearning", @id = model.Id })); } } return(View(model)); }
// CREATE CERTIFICATE BACKGROUND public ActionResult Create_Background() { CreateBackgroundModel model = new CreateBackgroundModel(); return(View(model)); }