Beispiel #1
0
        public void UpdateGoal(Goal goal)
        {
            var currentGoal = _goalContext.Goals.Find(goal.GoalId);

            if (currentGoal != null)
            {
                _goalContext.Entry(currentGoal).CurrentValues.SetValues(goal);
                _goalContext.SaveChanges();
            }
        }
Beispiel #2
0
        public async Task <IActionResult> PutGoal(int id, Goal goal)
        {
            if (id != goal.GoalId)
            {
                return(BadRequest());
            }

            _context.Entry(goal).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GoalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Edit([Bind(Include = "id,name,description,parent,sort")] Goal goal)
        {
            // Validation
            if (goal.name == null || goal.name.Trim().Length == 0)
            {
                ModelState.AddModelError("name", "Name is required.");
            }
            if (!unchecked (goal.parent == (int)goal.parent))
            {
                ModelState.AddModelError("parent", "Parent must be an integer.");
            }
            if (!unchecked (goal.sort == (int)goal.sort))
            {
                ModelState.AddModelError("sort", "Sort must be an integer.");
            }

            if (ModelState.IsValid)
            {
                goal.name = goal.name.Trim();

                db.Entry(goal).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(goal));
        }
        public async Task <ActionResult <Goal> > PutGoal(int id, Goal goal)
        {
            if (id != goal.GoalId)
            {
                return(BadRequest());
            }

            _context.Entry(goal).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(goal);
        }