Ejemplo n.º 1
0
        public async Task <ActionResult> CreateKid([FromBody] SaveKidResource newKid)
        {
            if (!(await _cabinRepository.CabinExistsAsync(newKid.CabinId)))
            {
                return(BadRequest());
            }

            var kidInDb = newKid.ToData();

            _kidRepository.Add(kidInDb);

            await _unitOfWork.CompleteAsync();

            kidInDb = await _kidRepository.GetKidAsync(kidInDb.Id, includeRelated : true);

            return(Ok(KidResource.FromData(kidInDb, includeRelated: true)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create(KidCreateViewModel model)
        {
            var username           = _httpContextAccessor.HttpContext?.User.Identity.Name;
            var currentUserProfile = _userMananger.Users.FirstOrDefault(u => u.UserName == username);

            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedImage(model);
                Kid    newKid         = new Kid()
                {
                    Name              = model.Name,
                    PhotoPath         = uniqueFileName,
                    ApplicationUserId = currentUserProfile.Id
                };

                _kidRepository.Add(newKid);
                await _kidRepository.CommitAsync();

                var toastobj = Helper.getToastObj("Kid profile was created successfully", "alert-success");
                TempData.Put("toast", toastobj);
                return(RedirectToAction("List"));
            }
            return(View(model));
        }