// [Authorize(Roles = "Admin, CourseManager")] public async Task<ActionResult> Create(/*[Bind(Include = "ID,Title,Description,Topic_ID,FactType_ID")]*/ Fact fact, string nameOfNewFactType, HttpPostedFileBase file, String fileSite) { ViewBag.Message = ""; /* if (ModelState.IsValid) {*/ db.Facts.Add(fact); //adding new FactType if (fact.FactType_ID == 0 || (fact.FactType_ID == 1 && nameOfNewFactType != "")) { if (fact.FactType_ID == 0 && (nameOfNewFactType == null || nameOfNewFactType == "")) { ViewBag.Message = "Введiть тип події"; ViewBag.FactType_ID = new SelectList(db.FactTypes, "ID", "Name", fact.FactType_ID); ViewBag.Topic_ID = fact.Topic_ID; return View(fact); } if (fact.FactType_ID != 0) { //var allFactTypes = from element in db.FactTypes // select db.FactTypes; foreach (var item in db.FactTypes) { if (nameOfNewFactType == item.Name) { ViewBag.Message = "Дана подiя вже iснує"; ViewBag.FactType_ID = new SelectList(db.FactTypes, "ID", "Name", fact.FactType_ID); ViewBag.Topic_ID = fact.Topic_ID; return View(fact); } } } FactType newFactType = new FactType(); newFactType.ID = fact.FactType_ID; newFactType.Name = nameOfNewFactType; db.FactTypes.Add(newFactType); db.SaveChanges(); } //uploading files to server if (file != null) { fact.FactUploadFiles.Add(new FactUploadFile { FactID = fact.ID, UploadFile = Saver.SaveFileToFolder(file.FileName, file, Server.MapPath(fileMapSource)) }); } await db.SaveChangesAsync(); return RedirectToAction("Index", "Courses"); /* }*/ /*ViewBag.FactType_ID = new SelectList(db.FactTypes, "ID", "Name", fact.FactType_ID); ViewBag.Topic_ID = new SelectList(db.Topics, "ID", "Title", fact.Topic_ID); return View(fact);*/ }
public async Task<ActionResult> Edit(/*[Bind(Include = "ID,Title,Description,Topic_ID,FactType_ID")] */Fact fact, int id) { /* if (ModelState.IsValid) {*/ UpdateModel(fact.Description); //db.Entry(fact.Description).State = EntityState.Modified; //db.Facts.Add(fact); await db.SaveChangesAsync(); return RedirectToAction("Index", "Topics", new { id = fact.Topic_ID }); /* }*/ //ViewBag.FactType_ID = new SelectList(db.FactTypes, "ID", "Name", fact.FactType_ID); //ViewBag.Topic_ID = new SelectList(db.Topics, "ID", "Title", fact.Topic_ID); //return View(fact); }