Esempio n. 1
0
        public async Task <IActionResult> Perform(PerformViewModel Model)
        {
            var student = await Manager.FindByNameAsync(User.Identity.Name);

            var task = Docs.Tasks.FirstOrDefault(x => x.StTaskID == Model.Answer.StTaskID && x.UserID == Model.Answer.UserID && Model.Answer.UserID == student.Id);

            if (task == null)
            {
                return(LocalRedirect(Model.returnUrl));
            }
            task.IsChecked = false;
            Docs.UpdateTask(task);
            Docs.AddAnswer(Model.Answer);
            return(LocalRedirect(Model.returnUrl));
        }
Esempio n. 2
0
        public IActionResult Rate(RateTaskViewModel model)
        {
            var task = Documentation.Tasks.FirstOrDefault(x => x.StTaskID == model.TaskID);

            if (task.MaxCost < model.CurrentRate)
            {
                ModelState.AddModelError("", "Rate cannot be more than " + model.MaxRate);
            }
            if (ModelState.IsValid)
            {
                var oldrate = task.CurrentCost;

                task.CurrentCost = model.CurrentRate;
                task.IsChecked   = true;
                Documentation.UpdateTask(task);
                if (model.CurrentRate != oldrate)
                {
                    var answer = new Answer()
                    {
                        AnswerDate = DateTime.Now,
                        StTaskID   = task.StTaskID,
                        TextData   = $@"Оцінка була змінена з {oldrate} до {model.CurrentRate}",
                        UserID     = Context.Users.FirstOrDefault(x => x.UserName == User.Identity.Name).Id
                    };

                    Documentation.AddAnswer(answer);
                }
                if (!String.IsNullOrEmpty(model.Description))
                {
                    var answer = new Answer()
                    {
                        AnswerDate = DateTime.Now,
                        StTaskID   = task.StTaskID,
                        TextData   = model.Description,
                        UserID     = Context.Users.FirstOrDefault(x => x.UserName == User.Identity.Name).Id
                    };

                    Documentation.AddAnswer(answer);
                }
                return(LocalRedirect(model.returnUrl));
            }
            return(View(model));
        }