Ejemplo n.º 1
0
 public ActionResult Create(Task task)
 {
     if (ModelState.IsValid)
     {
         Db.Add(task);
         return(RedirectToAction("Overview"));
     }
     return(View(task));
 }
Ejemplo n.º 2
0
        //OBRISI
        //On POst prima zadatak kojeg editiramo u POST FORMI, jer smo stavili da je MYTASK = BindProperty, tako da smo "uzeli" taj zadatak i dalje s njim
        // mozemo baratati u OnPost metodi, tako cu isto napraviti s "work" gumbom, koji ce mi biti on post :)
        public IActionResult OnPost()
        {
            SelectType = htmlHelper.GetEnumSelectList <TaskType>();

            if (ModelState.IsValid)
            {
                if (MyTask.Id > 0)
                {
                    MyTask = taskData.Update(MyTask);
                    TempData["Message"] = "Task updated!";
                }
                else
                {
                    MyTask = taskData.Add(MyTask);
                    TempData["Message"] = "Task saved!";
                }
                //taskData.Commit();
                return(RedirectToPage("./Detail", new { taskId = MyTask.Id }));
            }
            return(Page());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <TaskModel> > Post(TaskModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var task = _mapper.Map <Test.Core.Task>(model);
                _repository.Add(task);
                if (await _repository.SaveChangesAsync() == 1)
                {
                    return(Created($"/api/task/{task.Id}", _mapper.Map <TaskModel>(task)));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(BadRequest());
        }
Ejemplo n.º 4
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Status   = _htmlHelper.GetEnumSelectList <TaskStatus>();
                Priority = _htmlHelper.GetEnumSelectList <TaskPriority>();
                return(Page());
            }

            if (Task.Id > 0)
            {
                _taskData.Update(Task);
                TempData["Message"] = "Task updated!";
            }
            else
            {
                _taskData.Add(Task);
                TempData["Message"] = "Task added!";
            }

            _taskData.Commit();
            return(RedirectToPage("./Detail", new { taskId = Task.Id }));
        }