public HttpResponseMessage Post([FromBody] TicketDto ticketDto) { try { ticketDto.CurrUser = emp; // _employeeService.getEmplyByLoginName(RequestContext.Principal.Identity.Name); if (ticketDto.SourceId == 0) { ticketDto.SourceId = 3;//from web form } var message = ticketService.takeAction(new TicketDataParser(ticketDto)); var values = new { status = "success", message = message }; return(Request.CreateResponse(HttpStatusCode.OK, values)); } catch (Exception e) { var values = new { status = "failed", message = e.Message }; return(Request.CreateResponse(HttpStatusCode.InternalServerError, values)); } }
public IEnumerable <TicketDto> TicketByEmployer(TransByEmployerDTO requestParam) { IList <TicketDto> transDtoList = new List <TicketDto>(); var employees = _db2.Tickets.Where(o => o.AspNetUserId == requestParam.EmployerId).ToList(); foreach (var item in employees) { var transDto = new TicketDto() { Title = item.Title, Description = item.Description, CreatedAt = item.CreatedAt, TicketId = item.TicketId, noOfComments = item.Comment.Count().ToString() }; if (item.status == TicketStatus.Open) { transDto.Status = "Open"; } else { transDto.Status = "Close"; } transDtoList.Add(transDto); } return(transDtoList); }
public IHttpActionResult CreateTicket(TicketDto ticketDto) { /* The return type is IHttpActionResult to give more control over * the status code sent back to the client. */ if (!ModelState.IsValid) { BadRequest(); // implements the IHttpActionResultInterface } // Map to dto to domain model var ticket = Mapper.Map <TicketDto, Ticket>(ticketDto); // Update internal state data ticket.CreationDate = DateTime.Now; ticket.LastModified = ticket.CreationDate; ticket.IsOpen = true; // Add the new object to context and save changes _context.Tickets.Add(ticket); _context.SaveChanges(); ticketDto.Id = ticket.Id; // Return Unified Resource Identifier return(Created(new Uri(Request.RequestUri + "/" + ticket.Id), ticketDto)); }
public async Task <IActionResult> OnGetDetail(int ticketId) { TicketDto ticket = null; try { ticket = await ticketService.GetTicketAsync(ticketId); } catch (System.Exception e) { System.Console.WriteLine("Unable to fetch Ticket"); System.Console.WriteLine($"Error: {e.Message}"); System.Console.WriteLine($"Error Stack Trace: {e.StackTrace}"); } if (ticket != null) { return(new PartialViewResult { ViewName = "_TicketDetailPartial", ViewData = new ViewDataDictionary <TicketDto>(ViewData, ticket) }); } else { return(new PartialViewResult { ViewName = "_ErrorPartial", ViewData = new ViewDataDictionary <ErrorViewModel>(ViewData, new ErrorViewModel()) }); } }
public void Update_When_ticketDto_is_null_Then_throw_NullBodyException() { TicketDto nullDto = null; int id = 1; Assert.Throws <NullBodyException>(() => _service.Update(id, nullDto)); }
protected override TicketDto ticketDtoTransformation(RequestHeader item) { var sumittor = empRepo.Get(t => item.SubmittedBy.IndexOf(t.LoginName) > 0); var empDto = new EmployeeDto() { id = sumittor.Id, fullName = sumittor.DisplayName, email = sumittor.Email }; var ticket = new TicketDto() { ActivityCode = TicketActivityHandler.ACTIVITY_CODE, Subject = "K2 Form No: " + item.Title, Description = "Ticket posted by K2 form integration. For more detail, please go to the form", SourceId = 5, RequestorId = item.RequestorId, CurrUser = empDto, DeptOwnerId = 0, //TODO: get from DB IsFormIntegrated = true }; if (item.RequestCode == "GMU_REQ") { ticket.PriorityId = 2; } return(ticket); }
public async Task <ActionResult <TicketDto> > PutTicket(TicketDto dto) { if (dto == null || dto.Id < 1) { return(BadRequest()); } _logger.LogInformation(ApiLogEvents.UpdateItem, $"{nameof(PutTicket)} Started"); var repoObj = await _repository.GetId(dto.Id).ConfigureAwait(false); if (repoObj == null) { throw new Core.NotFoundException($"{nameof(PutTicket)}", dto.Id); } repoObj = _mapper.Map <Ticket>(dto); _repository.Update(repoObj); if (await _repository.SaveChangesAsync()) { return(_mapper.Map <TicketDto>(repoObj)); } else { return(Conflict("Failed, refresh and try again.")); } }
public async Task Handle(TicketCreateEvent message) { var priority = _priorityRepository.Find(message.PriorityId); var status = _statusRepository.Find(message.StatusId); await Task.WhenAll(priority, status); var ticket = new TicketDto { Id = message.AggregateRootId.ToString(), Description = message.Description, Title = message.Title, Priority = priority.Result, Status = status.Result, Files = message.Files?.Select(f => new FileDto { Id = f.Id.ToString(), Name = f.Name, Type = f.Type, Size = f.Size }).ToList() }; var @event = new CreatedEventDto { Id = Guid.NewGuid().ToString(), TicketId = message.AggregateRootId.ToString(), Created = message.Created, UserId = message.UserId.ToString(), }; await Task.WhenAll(AddInDb(ticket, @event), EmitToFrontEnd(ticket, @event)); }
public async Task UpdateAsync(Guid teamId, TicketDto ticketDto) { var ticketToUpdate = _mapper.Map <Ticket>(ticketDto); await _tagService.AddAsync(ticketDto.Tags); await _unitOfWork.Tickets.UpdateAsync(teamId, ticketToUpdate); var tickets = await _unitOfWork.Tickets.GetAll(teamId); foreach (var ticket in tickets) { if (ticketDto.LinkedTicketIds.Contains(ticket.Id) && !ticket.LinkedTicketIds.Contains(ticketDto.Id)) { ticket.LinkedTicketIds = ticket.LinkedTicketIds.Append(ticketDto.Id); await _unitOfWork.Tickets.UpdateAsync(teamId, ticket); } else if (!ticketDto.LinkedTicketIds.Contains(ticket.Id) && ticket.LinkedTicketIds.Contains(ticketDto.Id)) { ticket.LinkedTicketIds.ToList().Remove(ticketDto.Id); await _unitOfWork.Tickets.UpdateAsync(teamId, ticket); } } _logger.LogInformation($"Ticket with id {ticketDto.Id} was successfully updated "); }
public void Update(TicketDto ticketDto) { Ticket ticketToUpdate = uow.Tickets.Get(ticketDto.Id); mapper.Map(ticketDto, ticketToUpdate); var ticketAreas = uow.TicketArea.GetAll().Where(t => t.TicketId == ticketToUpdate.Id).ToList(); foreach (var ticketArea in ticketAreas) { uow.TicketArea.Delete(ticketArea); } foreach (var areaId in ticketDto.SelectedAreaIds) { uow.TicketArea.Create(new TicketArea() { TicketId = ticketToUpdate.Id, AreaId = areaId }); } uow.Save(); uow.Tickets.Update(ticketToUpdate); uow.Save(); }
public async Task Update(TicketDto item) { var updItem = _mapper.Map <TicketDto, Ticket>(item); await _unitOfWork.Repository <Ticket>().Update(updItem); await _unitOfWork.SaveAsync(); }
public async Task <int> Create(TicketDto ticketDto) { var creatorId = _dbContext.Accounts.Where(x => x.Name.Equals(ticketDto.Username)) .FirstOrDefault().AccountId; if (ticketDto.Sha256Checksum != null) { ticketDto.Sha256Checksum = ticketDto.Sha256Checksum.ToUpper(); } var ticket = new Ticket { CreatorId = creatorId, Description = ticketDto.Description, DownloadUrl = ticketDto.DownloadUrl, Severity = ticketDto.Severity, Sha256Checksum = ticketDto.Sha256Checksum, Solved = false }; await _dbContext.Tickets.AddAsync(ticket); await _dbContext.SaveChangesAsync(); return(ticket.Id); }
public TicketThreadObject(TicketDto ticket, PriorityValue priorityValue, IEnumerable <ForwarderMessage> forwarderMessages) { Ticket = ticket; PriorityValue = priorityValue; ForwarderMessages.AddRange(forwarderMessages); }
public void SetUp() { _ticketDbServiceMock = new Mock <ITicketDbService>(); _validTicket = new Ticket { Id = "1", Customer = new Customer { Id = "1", EmailAddress = "*****@*****.**" }, Discount = new Discount { Id = "1", Description = "discount description", DiscountValueInPercentage = 25, Type = Discount.DiscountType.ForChild }, Group = new SightseeingGroup { Id = "1", MaxGroupSize = 30, SightseeingDate = DateTime.Now.AddDays(1) }, Tariff = new TicketTariff { Id = "1", DefaultPrice = 30, Description = "ticket price list description" }, PurchaseDate = DateTime.Now.AddDays(-1), TicketUniqueId = Guid.NewGuid().ToString() }; _validTicketDto = new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("discount", "discounts/1", "GET") }.AsEnumerable(), PurchaseDate = DateTime.Now.AddDays(-1), TicketUniqueId = Guid.NewGuid().ToString() }; _logger = Mock.Of <ILogger <TicketsController> >(); _mapperMock = new Mock <IMapper>(); _mapperMock.Setup(x => x.Map <TicketDto>(It.IsAny <Ticket>())).Returns(_validTicketDto); _mapperMock.Setup(x => x.Map <Ticket>(It.IsAny <TicketDto>())).Returns(_validTicket); }
public TicketDto ModelToDto(Ticket ticket) { if (ticket == null) { return(null); } TicketDto dto = new TicketDto { Id = ticket.Id, OpenDateTime = ticket.OpenDateTime.ToString(), CloseDateTime = ticket.CloseDateTime.ToString(), CustomerName = ticket.CustomerName, Subject = ticket.Subject, Description = ticket.Description, PriorityName = ticket.Priority.Name, ServiceTypeName = ticket.ServiceType.Name, StatusName = ticket.Status.Name, TicketTypeName = ticket.TicketType.Name, UserName = ticket.User.UserName, UserEmail = ticket.User.Email }; return(dto); }
public void Update_WhenDtoIsPassed_ThenReturnedTheSameWithPassedId() { // Arrange var id = Guid.NewGuid(); var flightId = Guid.NewGuid(); var dto = new TicketDto() { FlightId = flightId, Price = 100 }; A.CallTo(() => unitOfWorkFake.FlightRepository.Get(flightId)).Returns(new Flight { Id = flightId }); var service = new TicketService(unitOfWorkFake, mapper, alwaysValidValidator); // Act var returnedDto = service.Update(id, dto); // Assert Assert.True(returnedDto.Id != default(Guid)); Assert.AreEqual(dto.FlightId, returnedDto.FlightId); Assert.AreEqual(dto.Price, returnedDto.Price); }
public Ticket UpdateFromDto(TicketDto ticketDto) { TicketId = ticketDto.id; TitleName = ticketDto.title; CategoryName = ticketDto.group?.title; ReviewText = ticketDto.details; DateReview = !string.IsNullOrEmpty(ticketDto.date_review) ? DateTime.Parse(ticketDto.date_review) : default(DateTime); UserServerId = ticketDto.user?.binary_id; GroupId = ticketDto.group_id; OffersCount = ticketDto.offers_count; ListOfTagTitles.Clear(); if (ticketDto.tags != null) { foreach (var ticketTagDto in ticketDto.tags) { ListOfTagTitles.Add(ticketTagDto.title); } } ListOfUsers.Clear(); if (ticketDto.users != null) { foreach (var userTicketDto in ticketDto.users) { ListOfUsers.Add(new UserTicket().UpdateFromDto(userTicketDto)); } } return(this); }
public TicketDto Edit(TicketDto item) { Ticket ticket = _converter.DtoToModel(item); TicketDto ticketDto = _converter.ModelToDto(_repository.Edit(ticket)); return(ticketDto); }
/// <summary> /// This method shows the information of the selected ticket /// <example>tickets/Details/1</example> /// <example>tickets/Details/4</example> /// </summary> /// <param name="id">ID of the selected ticket</param> /// <returns>Details of the ticket which ID is given</returns> public ActionResult Details(int id) { ShowTicket showTicket = new ShowTicket(); //Get the current ticket from the database string url = "TicketData/FindTicket/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { TicketDto SelectedTicket = response.Content.ReadAsAsync <TicketDto>().Result; showTicket.Ticket = SelectedTicket; //Get the user/owner of the selected ticket url = "TicketData/GetTicketUser/" + id; response = client.GetAsync(url).Result; ApplicationUserDto SelectedUser = response.Content.ReadAsAsync <ApplicationUserDto>().Result; showTicket.User = SelectedUser; //Get the parking spot of the selected ticket url = "TicketData/GetTicketSpot/" + id; response = client.GetAsync(url).Result; ParkingSpotDto SelectedSpot = response.Content.ReadAsAsync <ParkingSpotDto>().Result; showTicket.Spot = SelectedSpot; return(View(showTicket)); } else { return(RedirectToAction("Error")); } }
public void Create(TicketDto ticketDto) { var ticket = mapper.Map <TicketDto, Ticket>(ticketDto); ticket.Id = Guid.NewGuid(); ticket.CreatedUTCDate = DateTime.UtcNow; ticket.TicketType = uow.TicketTypes.Get(ticket.TicketTypeId); ticket.TransactionHistory = null; if (ticket.ActivatedUTCDate != null) { ticket.ExpirationUTCDate = ticket.ActivatedUTCDate?.AddHours(ticket.TicketType.DurationHours); } ticket.TicketArea = new List <TicketArea>(); foreach (var areaId in ticketDto.SelectedAreaIds) { TicketArea ticketArea = new TicketArea() { TicketId = ticket.Id, AreaId = areaId }; ticket.TicketArea.Add(ticketArea); } uow.Tickets.Create(ticket); uow.Save(); }
public async Task Create(TicketDto item) { var newItem = _mapper.Map <TicketDto, Ticket>(item); await _unitOfWork.Repository <Ticket>().Create(newItem); await _unitOfWork.SaveAsync(); }
public async Task CreateOrderAsync__Order_handle_succeeded__Should_return_201Created_with_order_data() { string orderId = "orderid"; var customerDto = new CustomerDto { Id = "1", DateOfBirth = _orderData.Customer.DateOfBirth, EmailAddress = _orderData.Customer.EmailAddress }; var ticketDtos = new TicketDto[] { new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("customer", "customers/1", "GET") } }, new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("customer", "customers/1", "GET") } } }.AsEnumerable(); SetUpForSucceededOrderHandling(orderId, customerDto, ticketDtos); var controller = new OrdersController(_orderHandlerMock.Object, _logger, _mapperMock.Object); var result = await controller.CreateOrderAsync(_orderData); (result as ObjectResult).StatusCode.Should().Be(201); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().BeEquivalentTo(new ApiError()); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Customer.Should().BeEquivalentTo(customerDto); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Tickets.Should().BeEquivalentTo(ticketDtos); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Id.Should().BeEquivalentTo(orderId); }
public List <TicketDto> GetAll() { List <TicketDto> allTickets = new List <TicketDto>(); using (_connection.OpenConnection()) { //@TODO: Make sure the user fields in this query are handled somewhere else. string query = "SELECT ticket.ticketID, p2.firstName, p2.lastName, p2.role, p2.email, subject, body, ticket.createdAt, lastEdited, status, priority, p2.personID " + "FROM ticket INNER JOIN personticket p on ticket.ticketID = p.ticketID INNER JOIN person p2 on p.personID = p2.personID"; using (MySqlCommand cmd = new MySqlCommand(query, _connection.GetConnection)) { var reader = cmd.ExecuteReader(); while (reader.Read()) { TicketDto ticket = new TicketDto() { Id = reader.GetInt32(0), Subject = reader.GetString(5), Content = reader.GetString(6), CreatedAt = reader.GetDateTime(7), LastEdited = reader.GetDateTime(8), Status = reader.GetString(9), Priority = reader.GetString(10), AuthorId = reader.GetInt32(11) }; allTickets.Add(ticket); } } } return(allTickets); }
public async Task GetOrderAsync__Order_data_retrieve_succeeded__Should_return_200OK_response_with_data() { string orderId = "orderid"; var customerDto = new CustomerDto { Id = "1", DateOfBirth = _orderData.Customer.DateOfBirth, EmailAddress = _orderData.Customer.EmailAddress }; var ticketDtos = new TicketDto[] { new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("customer", "customers/1", "GET") } }, new TicketDto { Id = "1", Links = new ApiLink[] { new ApiLink("customer", "customers/1", "GET") } } }.AsEnumerable(); _orderHandlerMock.Setup(x => x.GetCustomerAsync(It.IsAny <string>())).ReturnsAsync(new Customer { Id = "1", EmailAddress = "*****@*****.**" }); _orderHandlerMock.Setup(x => x.GetOrderedTicketsAsync(It.IsAny <string>())).ReturnsAsync(new Ticket[] { new Ticket { Id = "1" } }); SetUpMapper(customerDto, ticketDtos); var controller = new OrdersController(_orderHandlerMock.Object, _logger, _mapperMock.Object); var result = await controller.GetOrderAsync(orderId); (result as ObjectResult).StatusCode.Should().Be(200); ((result as ObjectResult).Value as ResponseWrapper).Error.Should().BeEquivalentTo(new ApiError()); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Customer.Should().BeEquivalentTo(customerDto); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Tickets.Should().BeEquivalentTo(ticketDtos); (((result as ObjectResult).Value as ResponseWrapper).Data as OrderResponseDto).Id.Should().BeEquivalentTo(orderId); }
// Létrehozás public async Task <TicketDto> CreateTicketAsync(TicketDto newTicketDto) { Ticket ticket = mapper.Map <Ticket>(newTicketDto); var result = await ticketRepository.CreateTicket(ticket); return(mapper.Map <TicketDto>(result)); }
public async Task <IActionResult> Create([FromBody] TicketDto model) { var currentUser = await _identityService.GetCurrentUser(); if (currentUser == null) { return(BadRequest(new { error = "You are not allowed!" })); } var person = await _identityService.GetPersonByUserId(currentUser.Id); if (person == null) { return(BadRequest(new { error = "Person was not found" })); } if (!ModelState.IsValid) { return(NotFound()); } if (model == null) { return(NotFound()); } var eventParent = await _eventParentService.GetEventParentById(model.EventParentId); if (eventParent == null) { return(BadRequest(new { error = "Selected event child was not found" })); } var ticketType = await _ticketTypeService.GetTicketTypeById(model.TicketTypeId); if (ticketType == null) { return(BadRequest(new { error = "Selected ticket type was not found" })); } var existingType = await _ticketService.ExistingTicketType(model.TicketTypeId, model.EventParentId, model.Id); if (existingType) { return(BadRequest(new { error = "Event child can not have the same ticket type twice" })); } var ticket = new Ticket() { EventParentId = model.EventParentId, TicketTypeId = model.TicketTypeId, Price = model.Price, Remaining = model.Remaining }; await _ticketService.CreateTicket(ticket); return(Ok()); }
public static TicketDto ConvertToTicketDto(ITicket ticket) { _ticketDto = new TicketDto() { Id = ticket.Id, Attachment = ticket.Attachment, AuthorId = ticket.AuthorId, Subject = ticket.Subject, Content = ticket.Content, CreatedAt = ticket.CreatedAt, LastEdited = ticket.LastEdited, Status = ticket.Status.ToString(), Priority = ticket.Priority.ToString() }; return(_ticketDto); }
public static ITicket ConvertToTicketObject(TicketDto dto) { _ticket = new Ticket() { Id = dto.Id, Attachment = dto.Attachment, AuthorId = dto.AuthorId, AgentId = dto.AgentId, Subject = dto.Subject, Content = dto.Content, CreatedAt = dto.CreatedAt, LastEdited = dto.LastEdited, Status = Enum.Parse <Status>(dto.Status), Priority = Enum.Parse <Priority>(dto.Priority) }; return(_ticket); }
private void AplyDtoToEntity(Ticket ticket, TicketDto ticketDto) { ticket.Place = ticketDto.Place; ticket.Price = ticketDto.Price; ticket.Time = ticketDto.Time; ticket.Stadium = ticketDto.Stadium; ticket.EventId = ticketDto.EventId; }
public TicketDto Add(TicketDto item) { item.OpenDateTime = DateTime.Now.ToString(); Ticket ticket = _converter.DtoToModel(item); TicketDto ticketDto = _converter.ModelToDto(_repository.Add(ticket)); return(ticketDto); }