Example #1
0
        public async Task <IActionResult> Post([FromBody] TravelDTO _travelDto)

        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string userId   = null;
            var    identity = HttpContext.User.Identity as ClaimsIdentity;

            if (identity != null)
            {
                userId = identity.FindFirst("userId").Value;
            }
            if (userId == null)
            {
                _logger.LogError("Le user ID dans le claims  est null !");
                throw new NotAuthorizException(ErrorConstants.BLASACARUnauthorized);
            }

            var TravelEntity = _mapper.Map <Travel>(_travelDto);

            TravelEntity.Userid = userId;
            var newTravelResult = await _TravelGenericServices.AddAsync(TravelEntity);

            if (newTravelResult is null)
            {
                _logger.LogError("Un problème au niveau de la création du Travel est survenu ");
                throw new BadRequestException(ErrorConstants.BLASACARTravelfailedCreation);
            }

            return(Ok(newTravelResult));
        }
Example #2
0
        public async Task <IActionResult> UpdateAsync([FromBody] TravelDTO _travelDto)
        {
            var TravelEntity = _mapper.Map <Travel>(_travelDto);

            string userId   = null;
            var    identity = HttpContext.User.Identity as ClaimsIdentity;

            if (identity != null)
            {
                userId = identity.FindFirst("userId").Value;
            }
            if (userId == null)
            {
                throw new NotAuthorizException(ErrorConstants.BLASACARUnauthorized);
            }

            TravelEntity.Userid = userId;

            var newTravelResult = await _TravelGenericServices.UpdateAsync(TravelEntity);

            if (newTravelResult is null)
            {
                _logger.LogError("Le Travel ID : " + (string.IsNullOrEmpty(TravelEntity.Id.ToString()) ? "Null" : TravelEntity.Id.ToString()) + ", n'existe pas dans la base de données");
                throw new NotFoundException(ErrorConstants.BLASACARTravelNotFoundException);
            }

            return(Ok(_mapper.Map <TravelDTO>(newTravelResult)));
        }
        public IEnumerable <PlaceToVisit> GetPlacesForTravelIdData([FromBody] TravelDTO travel)
        {
            var places = _context.Places.Where(p => p.CityId == travel.CityId)
                         .Where(P => P.PriceType == travel.PriceType)
                         .ToArray();

            return(places);
        }
        public IEnumerable <PlaceToVisit> GetPlacesForTravel([FromBody] TravelDTO travel)
        {
            var CityId = _context.Cities.Where(c => c.Name == travel.CityName).Select(c => c.Id).First();
            var places = _context.Places.Where(p => p.CityId == CityId)
                         .Where(P => P.PriceType == travel.PriceType)
                         .ToArray();

            return(places);
        }
        public async Task <ActualResult> CreateAsync(TravelDTO dto)
        {
            if (!await CheckNameAsync(dto.Name))
            {
                await _database.EventRepository.Create(_mapperService.Mapper.Map <Event>(dto));

                return(_mapperService.Mapper.Map <ActualResult>(await _database.SaveAsync()));
            }
            return(new ActualResult(Errors.DuplicateData));
        }
Example #6
0
        public async Task <TravelDTO> GetTravelByIdAsync(int tId)
        {
            var travel = await TravelRepository.GetSingleModelAsync(t => t.id == tId);

            TravelDTO travelDTO = Mapper.Map <TravelDTO>(travel);
            List <FileAttachmentEntity> fileAttachments = await _travelFileAttachmentService.GetTravelFileListByTravelId(travel.id);

            travelDTO.imgList = Mapper.Map <List <FileAttachmentDTO> >(fileAttachments);
            return(travelDTO);
        }
Example #7
0
        public void AddTravel([FromBody] TravelDTO travelDTO)
        {
            Travel travel = new Travel
            {
                UserId       = travelDTO.UserId,
                CityId       = dbcontext.Cities.Where(c => c.Name == travelDTO.CityName).Select(c => c.Id).First(),
                PriceType    = travelDTO.PriceType,
                PeopleAmount = travelDTO.PeopleAmount
            };

            dbcontext.Add(travel);
            dbcontext.SaveChanges();
        }
Example #8
0
        public async Task <ActualResult> UpdateAsync(TravelDTO dto)
        {
            try
            {
                _context.Entry(_mapper.Map <Event>(dto)).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ActualResult());
            }
            catch (Exception exception)
            {
                return(new ActualResult(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
Example #9
0
        public ActionResult PostCalculateComission([FromBody] TravelDTO travel)
        {
            Object result;

            try
            {
                result = _salesmanService.CalculateComission(travel.clientType, travel.passengers, travel.nights, travel.idsPackages);
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(result.GetType() == typeof(double) ? Ok(result) : StatusCode(400, result));
        }
        public async Task <ActualResult> CreateAsync(TravelDTO dto)
        {
            try
            {
                await _context.Event.AddAsync(_mapperService.Mapper.Map <Event>(dto));

                await _context.SaveChangesAsync();

                return(new ActualResult());
            }
            catch (Exception exception)
            {
                return(new ActualResult(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
        public async Task <ActualResult> UpdateAsync(TravelDTO dto)
        {
            var check = await _hashIdUtilities.CheckDecryptWithId(dto.HashId, Enums.Services.Travel);

            if (check.IsValid)
            {
                if (!await CheckNameAsync(dto.Name))
                {
                    await _database.EventRepository.Update(_mapperService.Mapper.Map <Event>(dto));

                    return(_mapperService.Mapper.Map <ActualResult>(await _database.SaveAsync()));
                }
                return(new ActualResult(Errors.DuplicateData));
            }
            return(new ActualResult(check.ErrorsList));
        }
Example #12
0
        public async Task <ActualResult <string> > CreateAsync(TravelDTO dto)
        {
            try
            {
                var travel = _mapper.Map <Event>(dto);
                await _context.Event.AddAsync(travel);

                await _context.SaveChangesAsync();

                var hashId = HashHelper.EncryptLong(travel.Id);
                return(new ActualResult <string> {
                    Result = hashId
                });
            }
            catch (Exception exception)
            {
                return(new ActualResult <string>(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
Example #13
0
        public async Task <IActionResult> CreateTravel(TravelDTO travelDTO)
        {
            //Check if the user is authenticated
            if (User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    //Add item with current traveler
                    var useraccount = await this._userManager.FindByNameAsync(User.Identity.Name);

                    Traveler traveler = this._travelerRepository.getTraveler(useraccount);
                    Travel   travel   = new Travel(travelDTO.Name)
                    {
                        Start = travelDTO.Start, End = travelDTO.End
                    };
                    traveler.Travels.Add(travel);
                    this._travelerRepository.SaveChanges();
                    return(Ok());
                }
                return(NoContent());
            }
            return(Unauthorized());
        }
        public async Task <ActionResult <TravelDTO> > GetAdminTravel([FromRoute] int id)
        {
            TravelDTO travelDTO = await _travelService.GetTravelByIdAsync(id);

            return(Ok(travelDTO));
        }