public bool DeleteCategories(Category category) { var context = new APPContext(); context.Entry(category).State = System.Data.Entity.EntityState.Deleted; return(context.SaveChanges() > 0); }
public bool SaveCategories(Category category) { var context = new APPContext(); context.Categories.Add(category); return(context.SaveChanges() > 0); }
public async Task <IActionResult> UploadToFileSystem(List <IFormFile> files, string description) { foreach (var file in files) { var basePath = Path.Combine(Directory.GetCurrentDirectory() + "\\Files\\"); bool basePathExists = System.IO.Directory.Exists(basePath); if (!basePathExists) { Directory.CreateDirectory(basePath); } var fileName = Path.GetFileNameWithoutExtension(file.FileName); var filePath = Path.Combine(basePath, file.FileName); var extension = Path.GetExtension(file.FileName); if (!System.IO.File.Exists(filePath)) { using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } var fileModel = new FileOnFileSystemModel { CreatedOn = DateTime.UtcNow, FileType = file.ContentType, Extension = extension, Name = fileName, Description = description, FilePath = filePath }; context.FileSOnFileSystemModel.Add(fileModel); context.SaveChanges(); } } TempData["Message"] = "File successfully uploaded to File System."; return(RedirectToAction("Index")); }
public void Save() { _context.SaveChanges(); }
public int Create(UserModel entity) { _appContext.Users.Add(entity); _appContext.SaveChanges(); return(entity.Id); }