Ejemplo n.º 1
0
        public async Task <Baby> CreateBaby(PostBabyDTO baby, string userId)
        {
            if (baby == null)
            {
                throw new ArgumentNullException(nameof(baby));
            }

            var users = unitOfWork.Users.GetAll();
            var user  = users.FirstOrDefault(
                user => user.Id == userId);

            var newBaby = new Baby()
            {
                Name       = baby.Name,
                BloodType  = baby.BloodType,
                Allergies  = baby.Allergies,
                Notes      = baby.Notes,
                GenderType = (GenderType)Enum.Parse(typeof(GenderType), baby.GenderType)
            };

            if (user != null)
            {
                newBaby.UserId = user.Id;
                newBaby.User   = user;

                unitOfWork.Babies.Create(newBaby);
                await unitOfWork.SaveChangesAsync();

                return(newBaby);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostBaby([FromRoute] string userId, [FromBody] PostBabyDTO baby)
        {
            //var postBabyDTO = new PostBabyDTO()
            //{
            //    Name = baby.Name,
            //    GenderType = baby.Name,
            //    BloodType = baby.BloodType,
            //    Allergies = baby.Allergies,
            //    Notes = baby.Notes
            //};

            var result = await babiesService.CreateBaby(baby, userId);

            if (result == null)
            {
                return(NotFound());
            }

            return(CreatedAtAction("GetBaby", new { id = result.Id }, baby));
        }