private void SafeSocialProgramImages(SocialProgramViewModel model, SocialProgram socialProgram) { if (model.ImageThumbnail != null) { string filename = socialProgram.Id + Path.GetExtension(model.ImageThumbnail.FileName); _fileUtility.SaveImage(model.ImageThumbnail.OpenReadStream(), "socialPrograms", "thumbnail", filename, new Size(_configuration.GetValue <int>("Images:ThumbnailSize:SocialPrograms:X"), _configuration.GetValue <int>("Images:ThumbnailSize:SocialPrograms:Y"))); socialProgram.ImageThumbnail = filename; } if (model.ImageLarge != null) { string filename = socialProgram.Id + Path.GetExtension(model.ImageLarge.FileName); _fileUtility.SaveImage(model.ImageLarge.OpenReadStream(), "socialPrograms", "images", filename, new Size(_configuration.GetValue <int>("Images:SocialPrograms:X"), _configuration.GetValue <int>("Images:SocialPrograms:Y"))); socialProgram.ImageLarge = filename; } if (model.ImageMobile != null) { string filename = socialProgram.Id + Path.GetExtension(model.ImageMobile.FileName); _fileUtility.SaveImage(model.ImageMobile.OpenReadStream(), "socialPrograms", "mobile", filename, new Size(_configuration.GetValue <int>("Images:MobileSize:SocialPrograms:X"), _configuration.GetValue <int>("Images:MobileSize:SocialPrograms:Y"))); socialProgram.ImageMobile = filename; } }
public IActionResult Post([FromForm] SocialProgramViewModel model) { SocialProgram socialProgram = new SocialProgram { DescriptionDe = model.DescriptionDe, DescriptionFr = model.DescriptionFr, NameDe = model.NameDe, NameFr = model.NameFr, StartTime = model.StartTime }; socialProgram.Order = _socialProgramsRepository.GetAll().Select(b => b.Order).DefaultIfEmpty(0).Max() + 1; _socialProgramsRepository.Add(socialProgram); SafeSocialProgramImages(model, socialProgram); _socialProgramsRepository.Update(socialProgram); return(CreatedAtRoute(GetSocialProgramRouteName, new { id = socialProgram.Id }, socialProgram)); }
public void Update(SocialProgram existingSocialProgram) { _context.SocialPrograms.Update(existingSocialProgram); _context.SaveChanges(); }
public void Delete(SocialProgram socialProgramToDelete) { _context.SocialPrograms.Remove(socialProgramToDelete); _context.SaveChanges(); }
public SocialProgram Add(SocialProgram socialProgram) { _context.SocialPrograms.Add(socialProgram); _context.SaveChanges(); return(socialProgram); }