private static RestResponse MapScience(AbstractResearchable science) { ScienceModel scienceModel = new ScienceModel(); scienceModel.Id = science.AssignedKey.Index; scienceModel.Key = science.GetKey(); scienceModel.Icon = science.GetIcon(); scienceModel.RequiredScienceBiome = science.RequiredScienceBiome; var unlocks = science.GetClientRecipeUnlocks(); if (unlocks != null) { scienceModel.Unlocks = unlocks.ToList(); } foreach (var item in science.GetConditions()) { if (item is ScientistCyclesCondition cycles) { scienceModel.ScientistCyclesCondition = cycles; } if (item is ColonistCountCondition count) { scienceModel.ColonistCountCondition = count; } } return(new RestResponse() { Content = scienceModel.ToUTF8SerializedJson() }); }
public ActionResult AddSciencePost(ScienceModel post) { if (ModelState.IsValid) { var ctx = new ApplicationDbContext(); ctx.SciencePost.Add(post); ctx.SaveChanges(); } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult NewSciencePostPartial() { var ctx = new ApplicationDbContext(); var userId = User.Identity.GetUserId(); var store = new UserStore <ApplicationUser>(new ApplicationDbContext()); var userManager = new UserManager <ApplicationUser>(store); ApplicationUser user = userManager.FindById(userId); var model = new ScienceModel { Author = User.Identity.Name, Date = DateTime.Now }; return(PartialView("NewSciencePostPartial", model)); }