public async Task <Boolean> Delete(int id) { var knowledge = await db.Knowledges.FindAsync(id); var acces = db.Accessories.Where(p => p.KnowledgeId == knowledge.Id).ToList(); foreach (var item in acces) { db.Accessories.Remove(item); } db.Knowledges.Remove(knowledge); int cout = await db.SaveChangesAsync(); if (cout != 0) { foreach (var item in acces) { var filePath = Server.MapPath("~/upfiles/" + item.FileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } return(true); } else { return(false); } }
public async Task <ActionResult> RoleMangar(string roleName) { db.Roles.Add(new IdentityRole(roleName)); await db.SaveChangesAsync(); var roles = db.Roles.ToList(); return(View(roles)); }