public async Task <IActionResult> Create(InfoViewModel model) { if (ModelState.IsValid) { //validate if branc code exist if (!await Task.Run(() => context.Exist <tblBranch>((x) => x.Id == model.Branch_FK))) { ViewBag.ErrorMessage = $"Brach with Id = {model.Branch_FK} cannot be found"; return(View("NotFound")); } //check if the user exist var user = await userManager.FindByIdAsync(model.User_FK); if (user == null) { ViewBag.ErrorMessage = $"User with Id = {model.User_FK} cannot be found"; return(View("NotFound")); } //instatiate new instance of tblInfo tblInfo table = new tblInfo() { Branch_FK = model.Branch_FK, Certificate = model.Certificate, Created = DateTime.Now, Id = Guid.NewGuid().ToString(), User_FK = model.User_FK }; await context.AddAsync <tblInfo>(table); return(RedirectToAction("index")); } //get all branch codes ViewBag.Branches = await context.GetAsync <tblBranch>(); return(View(model)); }
public virtual async Task <OpenTicketResult> Open(NewTicket newTicket) { if (newTicket == null) { throw new ArgumentNullException(nameof(newTicket)); } var validationResult = await _validator.ValidateAsync(newTicket); if (!validationResult.IsValid) { return(_factory.ValidationFailure(validationResult.Errors)); } var client = await _repository.SingleAsync(new GetClientById(newTicket.ClientId).AsNoTracking()); if (client == null) { return(_factory.ClientNotFound(newTicket.ClientId)); } if (newTicket.ProjectId.HasValue) { var project = await _repository.SingleAsync(new GetProjectById(newTicket.ProjectId.Value).AsNoTracking()); if (project == null) { return(_factory.ProjectNotFound(newTicket.ProjectId.Value)); } if (client.OrganizationId != project.OrganizationId) { return(_factory.ProjectInaccessible(client.ClientId, project.ProjectId)); } } var ticket = _mapper.Map <Ticket>(newTicket); await _repository.AddAsync(ticket); await _repository.SaveAsync(); var workflow = _workflowService.Process(new TicketOpenedWorkflow(ticket.TicketId)); var notification = _notificationService.Queue(new TicketOpenedNotification(ticket.TicketId)); await Task.WhenAll(workflow, notification); return(_factory.Opened(ticket)); }
public virtual async Task <ProcessResult> Link(int fromTicketId, int toTicketId, TicketLinkType linkType) { if (fromTicketId == toTicketId) { throw new ArgumentException("Cannot link a ticket to itself."); } if (_repository.SingleAsync(new GetTicketById(fromTicketId).AsNoTracking()) == null) { return(new TicketNotFoundResult(fromTicketId)); } if (_repository.SingleAsync(new GetTicketById(toTicketId).AsNoTracking()) == null) { return(new TicketNotFoundResult(toTicketId)); } var fromTicket = await _repository.GetAsync(new GetTicketLinkById(fromTicketId, toTicketId).AsNoTracking()); if (fromTicket != null) { return(new TicketsAlreadyLinkedResult(fromTicketId, toTicketId, fromTicket.LinkType)); } var toTicket = await _repository.GetAsync(new GetTicketLinkById(toTicketId, fromTicketId).AsNoTracking()); if (toTicket != null) { return(new TicketsAlreadyLinkedResult(toTicketId, fromTicketId, toTicket.LinkType)); } await _workflowService.Process(new BeforeTicketsLinkedWorkflow(fromTicketId, toTicketId, linkType)); var ticketLink = new TicketLink(fromTicketId, toTicketId); await _repository.AddAsync(ticketLink); await _repository.SaveAsync(); var workflow = _workflowService.Process(new TicketsLinkedWorkflow(fromTicketId, toTicketId, linkType)); var notification = _notificationService.Queue(new TicketsLinkedNotification(fromTicketId, toTicketId, linkType)); await Task.WhenAll(workflow, notification); return(new TicketsLinkedResult(fromTicketId, toTicketId, linkType)); }