public IActionResult Settings(Settings settings, IFormFile Logo, IFormFile Icon) { if (Logo != null) { _fileManager.Delete(_fileManager.GetWebRootPath() + settings.Logo); settings.Logo = _fileManager.Add(new FileModel { FormFile = Logo, IsWebRoot = true, Name = "logo", Path = "/notebook/images" }); } if (Icon != null) { _fileManager.Delete(_fileManager.GetWebRootPath() + settings.Icon); settings.Icon = _fileManager.Add(new FileModel { FormFile = Icon, IsWebRoot = true, Name = "favicon", Path = "" }); } _settingsManager.Update(settings); return(Redirect("/notebook-settings")); }
public IActionResult Add(IFormFile file) { var settings = _settingsManager.Table().FirstOrDefault(); if (file != null) { string fileExtension = file.FileName.Substring(file.FileName.LastIndexOf(".")); if (settings.AcceptedFileTypes.Contains(fileExtension)) { var user = HttpContext.Session.GetSession <User>("User"); _fileManager.Add(new FileModel { FormFile = file, IsWebRoot = true, Name = "", Path = $"/notebook/users/{user.Username}" }); } } return(Redirect("/documents")); }
private void UploadAvatar(IFormFile avatar, User user) { if (avatar != null) { if (user.Avatar != "/notebook/images/avatar.png") { _fileManager.Delete(_fileManager.GetWebRootPath() + user.Avatar); } user.Avatar = _fileManager.Add(new FileModel { FormFile = avatar, IsWebRoot = true, Name = "avatar", Path = "/notebook/users/" + user.Username }); } }