/// <summary>
        /// Creates the specified assignment.
        /// </summary>
        /// <param name="assignment">The assignment.</param>
        /// <returns></returns>
        public WorkerPersonAssignment Create(WorkerPersonAssignment assignment)
        {
            if (assignment == null)
            {
                throw new ArgumentNullException(nameof(assignment));
            }
            _assignmentRepository.Insert(assignment);

            return(assignment);
        }
Example #2
0
        public ActionResult AssignWorkerToCustomer(int requestId, string answer, int?workerId = null)
        {
            var errorMessage = string.Empty;

            if (!workerId.HasValue)
            {
                errorMessage = "Оберіть соціального робітника";
                return(Json(new { success = false, message = errorMessage }, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrWhiteSpace(answer))
            {
                errorMessage = "Додайте коментар";
                return(Json(new { success = false, message = errorMessage }, JsonRequestBehavior.AllowGet));
            }

            if (!ModelState.IsValid)
            {
                return(new ModelStateJsonResult(ModelState));
            }

            var careRequest = _customerService.GetCareRequestById(requestId);

            var currentUser    = HttpContext.User as CustomUser;
            var currentWorker  = _customerService.GetWorkerByUserId(currentUser.UserId);
            var assignedWorker = _customerService.GetWorkerByUserId(workerId.Value);

            careRequest.ReviewedById = currentWorker.Id;
            careRequest.ReviewedOn   = DateTime.UtcNow;
            careRequest.Answer       = answer;
            careRequest.StatusId     = (int)CareRequestStatuses.Approved;
            _customerService.UpdateCareRequest(careRequest);

            var person = _customerService.GetCustomerById(careRequest.CustomerId);

            person.StatusId = (int)CustomerCareStatuses.ПідДоглядом;

            var assignment = new WorkerPersonAssignment
            {
                CustomerId         = person.Id,
                AssignmentStatusId = (int)WorkerPersonAssignmentStatuses.Активно,
                CreatedOnUtc       = DateTime.UtcNow,
                WorkerId           = assignedWorker.Id,
                ReviewedByUserId   = currentUser.UserId,
            };

            _customerService.InsertAssignment(assignment);
            _customerService.Update(person);

            var custUser     = _customerService.GetCustomerById(careRequest.CustomerId);
            var notification = new Notification
            {
                IsOpened     = false,
                IsPositive   = true,
                Text         = answer,
                CreatedOnUtc = DateTime.UtcNow,
                UserId       = custUser.UserId
            };

            _customerService.InsertNotification(notification);

            return(Json(new { success = true, message = "Ваші зміни збережені" }, JsonRequestBehavior.AllowGet));
        }