public ActionResult DeleteConfirmed(int id) { ProjectCategories projectCategories = db.ProjectCategories.Find(id); db.ProjectCategories.Remove(projectCategories); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,ProjectProjectId,CategoryCategoryId")] ProjectCategories projectCategories) { if (ModelState.IsValid) { db.Entry(projectCategories).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProjectProjectId = new SelectList(db.Projects, "ProjectId", "ProjectTitle", projectCategories.ProjectProjectId); ViewBag.CategoryCategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", projectCategories.CategoryCategoryId); return(View(projectCategories)); }
// GET: ProjectCategories/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProjectCategories projectCategories = db.ProjectCategories.Find(id); if (projectCategories == null) { return(HttpNotFound()); } return(View(projectCategories)); }
// GET: ProjectCategories/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProjectCategories projectCategories = db.ProjectCategories.Find(id); if (projectCategories == null) { return(HttpNotFound()); } ViewBag.ProjectProjectId = new SelectList(db.Projects, "ProjectId", "ProjectTitle", projectCategories.ProjectProjectId); ViewBag.CategoryCategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", projectCategories.CategoryCategoryId); return(View(projectCategories)); }
public Result <bool> AddCategoryToProject(string email, int projectId, string categoryName) { //cheking if the email is valid if (!IsvalidEmail(email)) { resultbool.ErrorCode = 1; resultbool.ErrorText = "not valid email"; resultbool.Data = false; return(resultbool); } //chek if the projce exist if (!IfProjectExist(projectId)) { resultbool.ErrorCode = 8; resultbool.ErrorText = "projet doesn’t exist"; resultbool.Data = false; return(resultbool); } //cheking if the specific user can modify this projet if (!IsValidateUser(email, projectId)) { resultbool.ErrorCode = 3; resultbool.ErrorText = "This user can't modify this project"; resultbool.Data = false; return(resultbool); } //cheking if the project has already this category var projectCategory = context.Set <ProjectCategories>().Where(p => p.ProjectId == projectId).ToList(); //if (projectCategory.Any(pc => pc.Category.CategoryName == categoryName)) //{ // resultbool.ErrorCode = 2; // resultbool.ErrorText = "the project has already this category"; // resultbool.Data = false; // return resultbool; //} //create a new category var category = context.Set <Category>().SingleOrDefault(c => c.CategoryName == categoryName); if (category == null) { category = new Category(); category.CategoryName = categoryName; } context.Add(category); if (context.SaveChanges() < 1) { resultbool.ErrorCode = 4; resultbool.ErrorText = "couldnt save in db"; resultbool.Data = false; return(resultbool); } //create the projectcategory var project = context.Set <Project>().SingleOrDefault(p => p.ProjectId == projectId); var newProjectCategory = new ProjectCategories(); newProjectCategory.Project = project; newProjectCategory.ProjectId = project.ProjectId; newProjectCategory.Category = category; newProjectCategory.CategoryId = category.CategoryId; context.Add(newProjectCategory); if (context.SaveChanges() >= 1) { resultbool.ErrorCode = 0; resultbool.ErrorText = "Successfull"; resultbool.Data = true; return(resultbool); } else { resultbool.ErrorCode = 4; resultbool.ErrorText = "couldnt save in db"; resultbool.Data = false; return(resultbool); } }