Ejemplo n.º 1
0
        public async Task <Trip> Add(Trip item)
        {
            var result = await service.Add(item);

            result = service.Get(result.TripID);
            if (result.OrganizerID.HasValue)
            {
                var org = employee.Get(result.OrganizerID ?? 0);
                foreach (var emp in item.EmployeesToTrip)
                {
                    sender.Send(emp.Employee.Email, emp.Employee.Name, "Trip was created",
                                "A new trip was created where you were listed as a traveler. \r\n" +
                                "\r\n" +
                                "Trip details:\r\n" +
                                "\r\n" +
                                $"{result.DepartureOffice.City} - {result.ArrivalOffice.City}\r\n" +
                                $"{result.DepartureDate} - {result.ReturnDate}\r\n" +
                                $"Organizer: {org.Name} ({org.Email})\r\n" +
                                "\r\n" +
                                "The trip is now visible in your trips list.\r\n" +
                                "Please approve the trip and choose whether you will need an apartment to stay during your trip."
                                );
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public bool AddNew()
        {
            _tripService.Add(new Entities.Entities.TripEntity()
            {
                Name        = "Test trip",
                Description = "Test trip to the tes location"
            });

            return(true);
        }
Ejemplo n.º 3
0
 public IActionResult Add([FromBody] Trip trip)
 {
     try
     {
         _tripService.Add(trip);
         return(Ok(ServiceResponseExtension.TripCreatedSuccessfully));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.HResult, ex.InnerException == null ? ex.Message : ex.InnerException.Message);
         return(BadRequest(ServiceResponseExtension.GenericResponse));
     }
 }
Ejemplo n.º 4
0
        private void AddTrip(Trip trip, ITripService tripService, IAreaService areaService, IUserService userService)
        {
            trip.User = userService.FindByEmail(trip.User.Email);
            if (trip.User == default(User))
            {
                throw new Exception("User doesn't exists.");
            }

            trip.Area = areaService.FindById(trip.Area.Id);
            if (trip.Area == default(Area))
            {
                throw new Exception("Area doesn't exists.");
            }
            tripService.Add(trip);
        }
Ejemplo n.º 5
0
 public IHttpActionResult Post([FromBody] Trip trip)
 {
     try
     {
         bool insertSuccess = _tripService.Add(trip);
         if (!insertSuccess)
         {
             return(InternalServerError());
         }
         return(Ok());
     }
     catch (Exception e)
     {
         return(InternalServerError());
     }
 }
Ejemplo n.º 6
0
 public IActionResult Post([FromBody] Trip trip)
 {
     try
     {
         bool insertSuccess = _tripService.Add(trip);
         if (!insertSuccess)
         {
             return(StatusCode(500));
         }
         return(Ok());
     }
     catch (Exception e)
     {
         return(StatusCode(500));
     }
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> Add([FromBody] CreateTrip item)
        {
            var trip = new Trip
            {
                ArrivalOfficeID         = item.ArrivalOfficeID,
                DepartureDate           = item.DepartureDate,
                DepartureOfficeID       = item.DepartureOfficeID,
                IsPlaneNeeded           = item.IsPlaneNeeded,
                IsCarCompensationNeeded = item.IsCarCompensationNeeded,
                IsCarRentalNeeded       = item.IsCarRentalNeeded,
                ReturnDate      = item.ReturnDate,
                Status          = "CREATED",
                OrganizerID     = User.GetEmpoeeID(),
                EmployeesToTrip = item.Employees.Select(employee => new EmployeeToTrip
                {
                    EmployeeID = employee,
                    Status     = "PENDING",
                    WasRead    = false,
                }).ToList(),
            };
            var result = await service.Add(trip);

            //foreach (var employee in item.Employees)
            //{
            //    var employeeToTrip = new EmployeeToTrip
            //    {
            //        EmployeeID = employee,
            //        TripId = result.TripID,
            //        Status = "PENDING",
            //        WasRead = false,
            //    };
            //    await employeeToTripService.Add(employeeToTrip);
            //}

            return(Ok());
        }
        public async Task <IActionResult> Create([FromBody] AddTripInput input)
        {
            await _tripService.Add(input);

            return(_tripPresenter.ViewModel);
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <Trip> > PostTrip([FromBody] Trip trip)
        {
            await _tripService.Add(trip);

            return(CreatedAtAction("GetTrip", new { id = trip.Id }, trip));
        }