public async Task <IActionResult> AddToDo()
        {
            using (var reader = new StreamReader(Request.Body))
            {
                var json = reader.ReadToEnd();
                var item = JsonConvert.DeserializeObject <ToDoItem>(json);

                //client handling
                if (item.Title == "")
                {
                    return(BadRequest());
                }

                //if a server error occured, the returned GUID will be the default value
                //using this to decide returned status code
                var serviceResponse = await _toDoService.Add(item);

                if (serviceResponse == default(Guid))
                {
                    return(StatusCode(503)); //Service Unavailable
                }
                else
                {
                    var output = new JsonResult(serviceResponse);
                    output.StatusCode = 201;
                    return(output); //Created
                }
            }
        }
Beispiel #2
0
        public IActionResult Create(ToDoView item)  //kreiranje novog itema( podeljeno na kontroler,service, repos)
        {
            var pom = _mapper.Map <ToDoModel>(item);
            var res = _toDoService.Add(pom);


            return(CreatedAtRoute("GetTodo", new { id = item.Id }, item));
        }
        public IActionResult Post([FromBody] ToDoDto toDo)
        {
            ToDo toAdd = _mapper.Map <ToDo>(toDo);

            _toDoService.Add(toAdd);

            toDo = _mapper.Map <ToDoDto>(toAdd);

            return(Ok(toDo.ToDoId));
        }
Beispiel #4
0
        public ActionResult Create(ToDo toDo)
        {
            if (!ModelState.IsValid)
            {
                return(View(toDo));
            }

            _toDoService.Add(toDo);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,IsDone")] ToDo toDo)
        {
            if (!ModelState.IsValid)
            {
                return(View(toDo));
            }

            await _toDoService.Add(toDo);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #6
0
        public ActionResult Create(ToDoItem item)
        {
            try
            {
                _service.Add(item);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public IActionResult Post([FromBody] ToDo newToDo)
        {
            try
            {
                // add the new todo
                _todoService.Add(newToDo);
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddToDo", ex.Message);
                return(BadRequest(ModelState));
            }

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new todo. E.g., /api/todos/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = newToDo.Id }, newToDo));
        }
Beispiel #8
0
        public object AddToDo(dynamic parameters)
        {
            var todoInfo         = this.Bind <ToDoItem>("ID", "Completed");
            var validationResult = this.Validate(todoInfo);

            if (!validationResult.IsValid)
            {
                return(Negotiate.WithModel(validationResult).WithStatusCode(HttpStatusCode.BadRequest));
            }

            try
            {
                _todoService.Add(todoInfo.Title, todoInfo.Description, todoInfo.Deadline);
            }
            catch (Exception)
            {
                return(HttpStatusCode.NotFound);
            }

            return(HttpStatusCode.OK);
        }
        public IActionResult Post([FromBody] ToDo newToDo)
        {
            // ???? how to do a custom error message ??
            // ???  below does nothing   ?????
            string Bad = "poop";

            if (newToDo.Description == Bad)
            {
                {
                    ModelState.AddModelError("Description", "Don't poop on my to do list, you!");
                }
            }
            //   ?? above does nothing ??
            try
            {
                // add the new todo
                _todoService.Add(newToDo);
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddToDo", ex.Message);
                return(BadRequest(ModelState));
            }

            /*   if (!ModelState.IsValid)
             * {
             *  return BadRequest(ModelState);
             * }
             *
             * // add the new todo
             * _todoService.Add(newToDo);   */

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new todo. E.g., /api/todos/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = newToDo.Id }, newToDo));
        }
Beispiel #10
0
 public async Task <IActionResult> Add([FromBody] CreateToDoVM data)
 {
     return(Created("", await toDoService.Add(data)));
 }
Beispiel #11
0
 public ToDoItem Add(ToDoItem item)
 {
     return(_service.Add(item.Title, item.Description, item.Deadline));
 }
 public void Add(ToDoDto toDoDto)
 {
     _toDoService.Add(toDoDto);
 }