Ejemplo n.º 1
0
 public IActionResult Post([FromBody] ChildModel childModel)
 {
     try
     {
         var child         = childModel.ToDomainModel();
         var newChild      = _childService.Add(child);
         var newChildModel = newChild.ToApiModel();
         return(Ok(newChildModel));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("AddChild", ex.Message);
         return(BadRequest(ModelState));
     }
 }
Ejemplo n.º 2
0
        public ActionResult CreateChild(ChildDTO childDTO, int week)
        {
            if (string.IsNullOrEmpty(childDTO.FullName))
            {
                return(RedirectToAction("Index", new { groupId = childDTO.GroupId, week }));
            }

            var user = GetUser();

            if (!AdminService.IsAdmin(user))
            {
                return(Unauthorized());
            }

            ChildService.Add(childDTO);

            return(RedirectToAction("Index", new { groupId = childDTO.GroupId, week }));
        }
Ejemplo n.º 3
0
        public IActionResult CreateChild(Child child)
        {
            if (ModelState.IsValid)
            {
                var newChild = new Child();
                newChild.FirstName   = child.FirstName;
                newChild.LastName    = child.LastName;
                newChild.IIN         = child.IIN;
                newChild.DateOfBirth = child.DateOfBirth;
                newChild.Phone       = child.Phone;

                newChild = _childService.Add(newChild);

                return(RedirectToAction(nameof(ListChildren)));
            }
            else
            {
                return(View());
            }
        }