public async Task ChangeProgressStatus(string userId, ToDoTaskChangeProgressStatusApiModel model) { var entity = await _repository.FirstOrDefaultAsync(x => x.Id == model.Id); if (entity == null) { throw new Exception("Todotask is not found"); } else if (entity.FromUserId != userId && entity.ToUserId != userId) { throw new Exception("Access denied for changing progress-status of todotask"); } else if (entity.ToUserId == userId && entity.ProgressStatus != ToDoTaskStatusEnum.Cancelled && model.ProgressStatus != ToDoTaskStatusEnum.Cancelled) { entity.ProgressStatus = model.ProgressStatus; } else if (entity.ToUserId == userId && entity.ProgressStatus == ToDoTaskStatusEnum.Cancelled && model.ProgressStatus != ToDoTaskStatusEnum.Cancelled) { throw new Exception("Access denied. You can't change progress-status of todotasks which are Cancelled"); } else if (entity.ToUserId == userId && model.ProgressStatus == ToDoTaskStatusEnum.Cancelled) { throw new Exception("Access denied for cancelling todotask"); } else if (entity.FromUserId == userId && entity.ProgressStatus == ToDoTaskStatusEnum.New && model.ProgressStatus == ToDoTaskStatusEnum.Cancelled) { entity.ProgressStatus = model.ProgressStatus; } else if (entity.FromUserId == userId && entity.ProgressStatus != ToDoTaskStatusEnum.New && model.ProgressStatus == ToDoTaskStatusEnum.Cancelled) { throw new Exception("Access denied. You can cancell only tasks which are in progress-status - NEW"); } else if (entity.FromUserId == userId && model.ProgressStatus != ToDoTaskStatusEnum.Cancelled) { throw new Exception("Access denied. You have access only for cancelling task"); } await _repository.Update(entity); }
public async Task <ActionResult <SuccessResponseApiModel <string> > > ChangeProgressStatus(string id, [FromBody] ToDoTaskChangeProgressStatusApiModel model) { model.Id = model.Id ?? id; var userId = GetUserId(); await _service.ChangeProgressStatus(userId, model); var taskResult = await _service.Get(model.Id); if (model.ProgressStatus == ToDoTaskStatusEnum.Cancelled) { await BroadcastMessageSignalR(NotificationTypeEnum.ChangeProgressStatus, taskResult, false, taskResult.ToUserId); } else { await BroadcastMessageSignalR(NotificationTypeEnum.ChangeProgressStatus, taskResult, false, taskResult.FromUserId); } return(SuccessResult(new SuccessResponseApiModel <string>() { Response = "success", Id = model.Id })); }