public IHttpActionResult SetNewGoal(NewGoalViewModel viewModel) { var plannerInDb = _context.Planners.Find(viewModel.PlannerId); if (plannerInDb == null) { return(NotFound()); } var projectInDb = _context.Projects.Find(viewModel.ProjectId); if (projectInDb == null) { return(NotFound()); } var goal = new Goal { DateAdded = DateTime.Today, ProjectId = viewModel.ProjectId, Name = viewModel.GoalName, StatusId = (int)GoalStatus.INPROCESS }; var addedGoal = _context.Goals.Add(goal); _context.SaveChanges(); return(Ok(addedGoal)); }
public static Goal ToModel(this NewGoalViewModel viewModel) { var date = DateTime.UtcNow; return(new Goal { Name = viewModel.Name, Description = viewModel.Description, State = State.Open, CreationDate = date, ModificationDate = date }); }
public async Task <ActionResult> New([Bind("Name", "Description")] NewGoalViewModel goal) { if (ModelState.IsValid) { var g = goal.ToModel(); g.UserId = GetUserId(); await _goals.AddAsync(g); return(RedirectToAction("Index")); } return(View(goal)); }
public NewGoalPage() { InitializeComponent(); BindingContext = new NewGoalViewModel(); }
public async Task <ActionResult <List <SavingGoal> > > Put([FromRoute] int id, [FromBody] NewGoalViewModel NewGoal) { var ChangedGoal = this.db.SavingGoal.First(SavingGoal => SavingGoal.Id == id); ChangedGoal.Goal = NewGoal.NewGoal; await this.db.SaveChangesAsync(); var results = this.db.SavingGoal.OrderBy(goal => goal.Id); return(results.ToList()); }