public async Task <IActionResult> Delete(string name) { try { string storageName = HttpContext.Session?.GetString("StorageName"); if (storageName == name) { return(new BadRequestObjectResult("Вы находитеся в этом хранилище")); } var storage = storageContext.Storages .Where(s => s.Name == name && s.User == User.Identity.Name) .FirstOrDefault(); var word = storageContext.Words .Where(w => w.Storage == name && w.User == User.Identity.Name) .FirstOrDefault(); if (storage == null) { return(new BadRequestObjectResult("Хранилище не найдено")); } storageContext.Remove(storage); if (word != null) { storageContext.Remove(word); } //if (storageDB.Connection != null) // storageDB = new LiteBase(); //var path = "wwwroot/Users/" + User?.Identity.Name + "/Storages/" + name + ".db3"; //if (System.IO.File.Exists(path)) // System.IO.File.Delete(path); //if(System.IO.Directory.Exists(GetDirFile(false) + name)) // System.IO.Directory.Delete(GetDirFile(false) + name, true); dataLite.Close(); dataLite.Delete(name); await storageContext.SaveChangesAsync(); } catch (Exception ex) { logger.LogInformation(ex.StackTrace); return(new BadRequestObjectResult(ex.Message)); } return(new OkObjectResult("Хранилище удалено")); }
public ActionResult Delete() { var department = _db.Departments.Find(Id); if (department == null) { return NotFound(); } _db.Remove(department); _db.SaveChanges(); return Ok(); }