public IActionResult Assign(int setID) { var saved = _context.worksets.FirstOrDefault(x => x.WorksetID == setID); var model = new CreateSetViewModel() { TimeAllowed = saved.Time_Allowed, RandomQuestions = saved.RandomOrdering, Groups = UserHelper.GetGroups(UserHelper.GetUserId(HttpContext.Session)), SetType = saved.SetType }; return(View(model)); }
/// <summary> /// Creates a new deck (a streamloots "set") with the specified name, and returns the setId for that deck. /// </summary> /// <param name="deckName">The name of the deck to create.</param> /// <returns>The setId of the new deck (streamloots "set")</returns> async Task <string> AddDeck(string deckName) { CreateSetViewModel setData = new CreateSetViewModel(); setData.name = deckName; setData.slug = STR_DragonHumpersSlug; setData.craftableCards = true; setData.@default = false; setData.imageUrl = "https://static.streamloots.com/b355d1ef-d931-4c16-a48f-8bed0076401b/collections/collection_icon_001.png"; SetViewModel setCardViewModel = await CreateSet(setData); return(setCardViewModel._id); }
public async Task <SetViewModel> CreateSet(CreateSetViewModel setData) { ByteArrayContent byteContent = ToSerializedBytes(setData); //string serializedBytes = byteContent.ReadAsStringAsync().GetAwaiter().GetResult(); HttpResponseMessage httpResponseMessage = await client.PostAsync($"https://api.streamloots.com/sets", byteContent); if (await ErrorsReported(httpResponseMessage)) { return(null); } string result = await httpResponseMessage.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <SetViewModel>(result)); }
/// <summary> /// This method opens the creation page of a new workset /// </summary> /// <returns></returns> public IActionResult Create() { // Checks if the user has the privilages to create a new workset if (UserHelper.UserInRole(UserHelper.GetUserId(HttpContext.Session), UserHelper.ROLE_TEACHER) || UserHelper.UserInRole(UserHelper.GetUserId(HttpContext.Session), UserHelper.ROLE_ADMIN)) { // Creates the new createworkset model var Model = new CreateSetViewModel(); // Gets the groups the teacher has access too from the database. Model.Groups = UserHelper.GetGroups(UserHelper.GetUserId(HttpContext.Session)); return(View(Model)); } // Errors if they do not have access. return(Unauthorized()); }
public IActionResult Assign(CreateSetViewModel model) { Worksets sets = new Worksets() { GroupID = model.GroupID, WorksetName = model.WorksetName, SetBy = UserHelper.GetUserId(HttpContext.Session), Time_Allowed = model.TimeAllowed, Date_Set = DateTime.Now.Date, SetType = model.SetType, Date_Due = model.Date_Due, ExamStyle = model.SelectFromList, RandomOrdering = model.RandomQuestions }; return(RedirectToAction("Set")); }
public IActionResult Create(CreateSetViewModel model) { // Checks that valid model has been returned if (!ModelState.IsValid) { model.Groups = UserHelper.GetGroups(UserHelper.GetUserId(HttpContext.Session)); return(View(model)); } // Creates the workset from the given information Worksets sets = new Worksets() { GroupID = model.GroupID, WorksetName = model.WorksetName, SetBy = UserHelper.GetUserId(HttpContext.Session), Time_Allowed = model.TimeAllowed, Date_Set = DateTime.Now.Date, SetType = model.SetType, Date_Due = model.Date_Due, ExamStyle = model.SelectFromList, RandomOrdering = model.RandomQuestions }; // Checks if the workset should have no group because it was saved for later if (sets.GroupID == -2) { sets.GroupID = null; } // Adds the workset to the database and gets its ID sets.WorksetID = DatabaseConnector.AddWorkset(sets); // Creates the model that nit used to build the workset var Model = new BuildViewModel() { WorkSetID = sets.WorksetID, createdWork = new CreatedWork() { SelectFromList = sets.ExamStyle, CatagoryTypes = GetAllQuestions() } }; return(View("Build", Model)); }