public async Task Assign(CaseAssignDTO dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } //Assignee must be CA var order = await DbContext.OnlineOrder.Where(o => o.OrderId == dto.Id).SingleOrDefaultAsync() ?? throw new BussinessException($"Order: {dto.Id} is not exists"); var assignee = await DbContext.AppUser.Where(u => u.UserId == dto.UserId).SingleOrDefaultAsync() ?? throw new BussinessException($"User: {dto.UserId} is not exists"); //Is stage valid? if (order.StageId != (int)StageEnum.NotAssignable) { throw new BussinessException($"Order: {dto.Id} current stage does not allow assigning"); } //BDS: Is assignee under this BDS? if (Role == RoleEnum.BDS) { if (assignee.ManagerId != UserId) { throw new BussinessException($"User: {dto.UserId} is not under current user management"); } } //Proceed order.AssignUserId = assignee.UserId; order.StageId = (int)StageEnum.CustomerConfirm; await DbContext.SaveChangesAsync(); _mail.MailNewAssign(order, assignee.Email, null); }
public async Task <IActionResult> Assign([FromBody] CaseAssignDTO dto) { if (!ModelState.IsValid) { return(BadRequest()); } try { await _service.Assign(dto); return(Ok()); } catch (BussinessException ex) { _logger.LogDebug(ex.Message); return(BadRequest(ex.Message)); } }