Ejemplo n.º 1
0
        public async Task <ActionResult> ChangeStatus(VTask vTask)
        {
            Kid currentKid = await _kidRepository.GetProfileById(vTask.KidId);

            if (ModelState.IsValid)
            {
                vTask.Done = !vTask.Done;
                _vTaskRepository.Update(vTask);
                await _vTaskRepository.CommitAsync();

                if (!vTask.Done)
                {
                    currentKid.TotalPoint -= vTask.Point;
                }
                else
                {
                    currentKid.TotalPoint += vTask.Point;
                }
                _kidRepository.Update(currentKid);
                await _kidRepository.CommitAsync();

                var toastobj = Helper.getToastObj("Task complete status updated!", "alert-success");
                TempData.Put("toast", toastobj);
                return(RedirectToAction("Details", "Kid", new { vTask.KidId }));
            }
            return(View(vTask));
        }
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));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Redeem(Reward reward)
        {
            Kid currentKid = await _kidRepository.GetProfileById(reward.KidId);

            if (ModelState.IsValid)
            {
                reward.Acquired = !reward.Acquired;
                if (reward.Acquired)
                {
                    if (currentKid.TotalPoint < reward.Point)
                    {
                        reward.Acquired = !reward.Acquired;
                        TempData.Put("toast", new Toaster {
                            Message = "Kid does not have enough point", CssClass = "alert-danger"
                        });
                        return(RedirectToAction("Details", "Kid", new { reward.KidId }));
                    }
                    else
                    {
                        currentKid.TotalPoint -= reward.Point;
                    }
                }
                else
                {
                    currentKid.TotalPoint += reward.Point;
                }
                var toastobj = Helper.getToastObj("Reward was redeemed successfully", "alert-danger");
                TempData.Put("toast", toastobj);
                _rewardRepository.Update(reward);
                await _rewardRepository.CommitAsync();

                _kidRepository.Update(currentKid);
                await _kidRepository.CommitAsync();

                return(RedirectToAction("Details", "Kid", new { reward.KidId }));
            }
            return(View(reward));
        }