コード例 #1
0
        /// <summary>
        /// Check flight number. It must be unique and isn't empty.
        /// </summary>
        /// <param name="result">Service answer, need for creation chain of checks.</param>
        /// <param name="Number">Flight number.</param>
        /// <returns>Boolean result of cheking.</returns>
        private bool CheckNumber(ServiceAnswer result, string Number)
        {
            if (result.Status == AnswerStatus.Failure)
            {
                return(false);
            }

            if (Number == string.Empty || Number == null)
            {
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Number error", "Flight number empty or null.");

                _logger.Warning("Flight number is empty");

                return(false);
            }

            var uniqeNumber = _flightRepository.FindByNumber(Number) == null ? true : false;

            if (!uniqeNumber)
            {
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Number error", "Flight number is not uniqe.");

                _logger.Warning($"Flight number '{Number}' is not uniqe");

                return(false);
            }

            return(true);
        }
コード例 #2
0
 public ServiceAnswer<IProject> GetById(Guid project_id)
 {
     var result = new ServiceAnswer<IProject>();
     try
     {
         IProject project = ProjectContext.Get(project_id);
         if (project == null)
         {
             result.CallResult = CallResult.NotFound;
             result.ErrorText = "Can't found project by id";
         }
         else
         {
             result.CallResult = CallResult.Ok;
             result.Data = project;
         }
     }
     catch (Exception ex)
     {
         result.CallResult = CallResult.ExceptionOccured;
         result.ErrorType = ex.GetType().FullName;
         result.ErrorText = ex.Message;
     }
     return result;
 }
コード例 #3
0
        /// <summary>
        /// Check that flight aircrew contain least one pilot.
        /// </summary>
        /// <param name="result">Service answer, need for creation chain of checks.</param>
        /// <param name="members">List of aircrew members identifiers.</param>
        /// <returns>Boolean result of cheking.</returns>
        private bool CheckExistencePilot(ServiceAnswer result, IEnumerable <Guid> members)
        {
            if (result.Status == AnswerStatus.Failure)
            {
                return(false);
            }

            try
            {
                var pilots = _aircrewMemberRepository.GetAll()
                             .Where(x => x.Profession.Name == "Pilot")
                             .Where(x => members.Contains(x.Id))
                             .Count();

                if (pilots == 0)
                {
                    result.Status = AnswerStatus.Failure;
                    result.Errors.Add("Pilot error", "In aircrew is no one pilot.");

                    _logger.Warning("Pilot was not found.");

                    return(false);
                }
            }
            catch (Exception exc)
            {
                _logger.Error($"Exception occurred during the checking the pilot in aircrew.\r\n Exception: {exc.ToString()}");

                return(false);
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Check correct of departure and arrival date. Departure date must be before arrival.
        /// </summary>
        /// <param name="result">Service answer, need for creation chain of checks.</param>
        /// <param name="departureDate">Departure date.</param>
        /// <param name="arrivalDate">Arival date.</param>
        /// <param name="isCheckDepartureAfterCurrent">Is add condition to check departure date. It must be after current.</param>
        /// <returns>Boolean result of cheking.</returns>
        private bool CheckDate(ServiceAnswer result, DateTime departureDate, DateTime arrivalDate, bool isCheckDepartureAfterCurrent = true)
        {
            if (result.Status == AnswerStatus.Failure)
            {
                return(false);
            }

            if (departureDate.Date < DateTime.Now.Date && isCheckDepartureAfterCurrent)
            {
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Date error", "Departure must be after or equal current date.");

                return(false);
            }

            if (departureDate.Date > arrivalDate.Date)
            {
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Date error", "Departure or arrival date is not valid.");

                _logger.Warning($"Departure or arrival date is not valid (dep. date: {departureDate.Date.ToString("dd-MM-yyyy")}, arriv. date {arrivalDate.Date.ToString("dd-MM-yyyy")})");

                return(false);
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Set new status to ser of aircrew members.
        /// </summary>
        /// <param name="aircrewMemberIds">Aircre members identifiers.</param>
        /// <param name="status">New status</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer SetStatus(IEnumerable <Guid> aircrewMemberIds, AircrewMemberStatus status)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start set aircrew members status method.");

            try
            {
                _aircrewMemberRepository.SetStatus(aircrewMemberIds, status);
                result.Status = AnswerStatus.Success;

                _logger.Info($"To group of aircrew members, ids:\r\n {aircrewMemberIds.GetStringsLits()} have been set new status: {status.ToString()}.");
            }
            catch (Exception exc)
            {
                _logger.Error($"Exception occurred during the setting new status of group aircrew members, ids:\r\n {aircrewMemberIds.GetStringsLits()}.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish set aircrew members status method.");

            return(result);
        }
コード例 #6
0
 public ServiceAnswer<ITask> Get(Guid task_id)
 {
     var result = new ServiceAnswer<ITask>();
     try
     {
         ITask task = TaskContext.Get(task_id);
         if (task == null)
         {
             result.CallResult = CallResult.NotFound;
             result.ErrorText = "Can't find task by id";
         }
         else
         {
             result.CallResult = CallResult.Ok;
             result.Data = task;
         }
     }
     catch (Exception ex)
     {
         result.CallResult = CallResult.ExceptionOccured;
         result.ErrorType = ex.GetType().FullName;
         result.ErrorText = ex.Message;
     }
     return result;
 }
コード例 #7
0
        /// <summary>
        /// Set status to selected flight.
        /// </summary>
        /// <param name="idFlight">Flight identifier.</param>
        /// <param name="status">Flight status.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer SetStatus(Guid idFlight, string status)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start set flight status method.");

            if (!GetAvailableStatuses().Result.Contains(status) || status == null)
            {
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Argument error", "Invalid value of status.");

                _logger.Warning($"Parametr status is invalid (value: {status??"empty"} ).");
                _logger.Debug("Finish set flight status method.");

                return(result);
            }

            try
            {
                var targetFlight = _flightRepository.FindById(idFlight);;
                if (targetFlight != null)
                {
                    _flightRepository.StartTransaction();

                    targetFlight.Status = GetEnumStatus(status, targetFlight.Status);

                    ManageAircrewByStatus(targetFlight);
                    SaveOrDisbandAircrew(targetFlight);

                    _flightRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"To flight (id: {idFlight}) has been set new status '{status}'");
                    _logger.Debug("Finish set flight status method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Finding error", "Flight is not found.");

                _logger.Warning($"Flight (id: {idFlight}) was not found.");
            }
            catch (Exception exc)
            {
                _flightRepository.RollBack();

                _logger.Error($"Exception occurred during the setting new status of flight, id: {idFlight} status: {status}.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish set flight status method.");

            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Update profession.
        /// </summary>
        /// <param name="profession">New profession data.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Update(ProfessionDto profession)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start update profession method.");

            try
            {
                var isUniqueName = IsUniqueName(profession.Name);
                if (isUniqueName)
                {
                    var targetProfession = _professionRepository.FindById(profession.Id);
                    if (targetProfession != null)
                    {
                        _professionRepository.StartTransaction();

                        targetProfession.Name = profession.Name;

                        _professionRepository.Commit();

                        result.Status = AnswerStatus.Success;

                        _logger.Info($"Updated profession (id: {profession.Id}).");
                        _logger.Debug("Finish update profession method.");

                        return(result);
                    }

                    result.Status = AnswerStatus.Failure;
                    result.Errors.Add("Finding error", "Profession was not found.");

                    _logger.Warning($"Profession (id: {profession.Id}) was not found.");
                    _logger.Debug("Finish update profession method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Updating error", $"Profession with name '{profession.Name}' already exists.");

                _logger.Warning($"Profession name '{profession.Name}' alredy used.");
            }
            catch (Exception exc)
            {
                _professionRepository.RollBack();

                _logger.Error($"Exception occurred during the updating  profession, id: {profession.Id}.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish update profession method.");

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Set aircrew member current location (city). Checks for the existence of a city.
        /// </summary>
        /// <param name="aircrewMemberId">Aircrew member identifier.</param>
        /// <param name="idCity">City identifier.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer SetCurrentLocation(Guid aircrewMemberId, Guid idCity)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start set aircrew member current location method.");

            try
            {
                var targetCity = _cityRepository.FindById(idCity);
                var targetUser = _aircrewMemberRepository.FindById(aircrewMemberId);
                if (targetCity != null)
                {
                    if (targetUser != null)
                    {
                        _aircrewMemberRepository.StartTransaction();

                        _aircrewMemberRepository.SetCity(targetUser, targetCity);

                        result.Status = AnswerStatus.Success;

                        _aircrewMemberRepository.Commit();

                        _logger.Info($"To aircrew member id: {aircrewMemberId} have been set new current position '{targetCity.Name}' that have id: {idCity}.");
                        _logger.Debug("Finish set aircrew member current location method.");

                        return(result);
                    }

                    result.Status = AnswerStatus.Failure;
                    result.Errors.Add("Finding error", "Required aircrew member was not found.");

                    _logger.Warning($"Required aircrew member (Id: {aircrewMemberId}) was not found.");
                }
                else
                {
                    result.Status = AnswerStatus.Failure;
                    result.Errors.Add("Finding error", "Required profession was not found.");

                    _logger.Warning($"Required city (Id: {idCity}) was not found.");
                }
            }
            catch (Exception exc)
            {
                _aircrewMemberRepository.RollBack();

                _logger.Error($"Exception occurred during the setting new current position of an aircrew member\r\n Id aircrew member: {aircrewMemberId}, Id city: {idCity}.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish set aircrew member current location method.");

            return(result);
        }
コード例 #10
0
        public async Task <IActionResult> GetByIdCredit(long idCredit)
        {
            (HttpStatusCode statusCode, string message, List <QuotaDataDto> response) =
                await _quotaBusiness.GetByCredit(idCredit);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <List <QuotaDataDto> > .Response(statusCode, message, response));
        }
コード例 #11
0
        public async Task <IActionResult> Create([FromBody] RequestClientDto requestClientDto)
        {
            (HttpStatusCode statusCode, string message, CreateClientResponseDto response) =
                await _clientsBusiness.CreateClientAsync(requestClientDto);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <CreateClientResponseDto> .Response(statusCode, message, response));
        }
コード例 #12
0
        public async Task <IActionResult> SimulateQuotas([FromBody] SimulateQuotasRequest simulateQuotasRequest)
        {
            (HttpStatusCode statusCode, string message, SimulateQuotasResponse response) =
                await _quotaBusiness.SimulateQuotas(simulateQuotasRequest);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <SimulateQuotasResponse> .Response(statusCode, message, response));
        }
コード例 #13
0
        public async Task <IActionResult> Create([FromBody] CreateQuotasRequest createQuotasRequest)
        {
            (HttpStatusCode statusCode, string message, bool response) =
                await _quotaBusiness.CreateQuotas(createQuotasRequest);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <bool> .Response(statusCode, message, response));
        }
コード例 #14
0
        public async Task <IActionResult> Scan([FromBody] IdScanRequest idScanRequest)
        {
            (HttpStatusCode statusCode, string message, IdScanResponse response) =
                await _idScanBusiness.Scan(idScanRequest);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <IdScanResponse> .Response(statusCode, message, response));
        }
コード例 #15
0
        public async Task <IActionResult> MasiveScan()
        {
            (HttpStatusCode statusCode, string message, bool response) =
                await _idScanBusiness.MasiveScan();

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <bool> .Response(statusCode, message, response));
        }
コード例 #16
0
        public async Task <IActionResult> GetInfoClient(long idClient)
        {
            (HttpStatusCode statusCode, string message, InfoClientResponseDto response) =
                await _clientsBusiness.GetInfoClientAsync(idClient);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            return(ServiceAnswer <InfoClientResponseDto> .Response(statusCode, message, response));
        }
コード例 #17
0
        /// <summary>
        /// Create answer to existing request with one of the statuses "Completed" or "Rejected".
        /// </summary>
        /// <param name="id">Flight request identifier.</param>
        /// <param name="isCompleted">true is "Completed" and false is Rejected</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer SetAnswerToRequest(Guid id, bool isCompleted)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start set answer to request method.");

            try
            {
                var targetRequest = _flightRequestRepository.FindById(id);

                if (targetRequest != null)
                {
                    var from     = targetRequest.To;
                    var to       = targetRequest.From;
                    var sendTime = DateTime.Now.Date;
                    var status   = isCompleted ? AdminAnswerStatus.Completed : AdminAnswerStatus.Rejected;
                    var message  = targetRequest.Message;

                    _flightRequestRepository.StartTransaction();

                    _flightRequestRepository.Delete(targetRequest);

                    _flightRequestRepository.Add(from, to, message, sendTime, status);

                    result.Status = AnswerStatus.Success;

                    _flightRequestRepository.Commit();

                    _logger.Info($"Added new flight request (answer) from: {from.Email}, to: {to.Email}");
                    _logger.Debug("Finish set answer to request method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Finding by id error", "Flight request is not found.");

                _logger.Warning($"Flight request (id: {id}) was not found.");
            }
            catch (Exception exc)
            {
                _logger.Error($"Exception occurred during the creating of an answer to flight request (id: {id}) flight requests.\r\n Exception: {exc.ToString()}");

                _flightRequestRepository.RollBack();
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish set answer to request method.");

            return(result);
        }
コード例 #18
0
        public async Task <IActionResult> Get(int idIdentificationType, string identification)
        {
            (HttpStatusCode statusCode, string message, ClientDataResponse response) =
                await _clientsBusiness.GetClientAsync(idIdentificationType, identification);

            if (statusCode != HttpStatusCode.NoContent && Response != null)
            {
                Response.StatusCode = (int)statusCode;
            }
            IActionResult actionResult = ServiceAnswer <ClientDataResponse> .Response(statusCode, message, response);

            return(actionResult);
        }
コード例 #19
0
        /// <summary>
        /// Create flight request.
        /// </summary>
        /// <param name="emailFrom">Sender e-mail.</param>
        /// <param name="emailTo">Receiver e-mail</param>
        /// <param name="message">Request message.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Create(string emailFrom, string emailTo, string message)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start create fligh request method.");

            try
            {
                var users = _userRepository.GetAll().Where(x => x.Email.ToUpper() == emailFrom.ToUpper() ||
                                                           x.Email.ToUpper() == emailTo.ToUpper())
                            .ToList();

                if (users.Count() == 2)
                {
                    var fromUser = users.First(x => x.Email == emailFrom);
                    var toUser   = users.First(x => x.Email == emailTo);
                    var Message  = message;

                    _flightRequestRepository.StartTransaction();

                    _flightRequestRepository.Add(fromUser, toUser, Message, DateTime.Now, AdminAnswerStatus.Undefined);

                    _flightRequestRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"Added new flight request\r\n From: {emailFrom}\r\n To: {emailTo}.");
                    _logger.Debug("Finish create fligh request method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Finding error", "One of the users is not found.");

                _logger.Warning($"User with e-mail: {emailTo} was not found.");
            }
            catch (Exception exc)
            {
                _flightRequestRepository.RollBack();

                _logger.Error($"Exception occurred during the adition of a new flight request.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish create fligh request method.");

            return(result);
        }
コード例 #20
0
        /// <summary>
        /// Set new status to aircrew member.
        /// </summary>
        /// <param name="userId">Aircrew member identifier.</param>
        /// <param name="status">New satus.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer SetNewStatus(Guid userId, string status)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start set aircrew member new status method.");

            try
            {
                var targetUser = _aircrewMemberRepository.FindById(userId);
                if (targetUser != null)
                {
                    var newStatus = GetEnumStatus(status, targetUser.Status);
                    if (newStatus != targetUser.Status)
                    {
                        _aircrewMemberRepository.StartTransaction();

                        targetUser.Status = newStatus;

                        _aircrewMemberRepository.Commit();
                    }

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"To aircrew member (id: {userId}) has been set new status: '{status}'.");
                    _logger.Debug("Finish set  aircrew member new status method.");

                    return(result);
                }
                else
                {
                    result.Status = AnswerStatus.Failure;
                    result.Errors.Add("Finding error", "Aircrew member was not found.");

                    _logger.Warning($"Aircrew member (id: {userId}) was not found.");
                }
            }
            catch (Exception exc)
            {
                _aircrewMemberRepository.RollBack();

                _logger.Error($"Exception occurred during the setting new status of an aircrew member.\r\n User id: {userId}, new status: {status} .\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish set  aircrew member new status method.");

            return(result);
        }
コード例 #21
0
        /// <summary>
        /// Create new city.
        /// </summary>
        /// <param name="cityName">City name.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Create(string cityName)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start create new city method.");

            try
            {
                var isUniqueName = _cityRepository.GetAll()
                                   .FirstOrDefault(x => x.Name.ToUpper().Equals(cityName.ToUpper())) == null ? true : false;

                if (isUniqueName)
                {
                    _cityRepository.StartTransaction();

                    _cityRepository.Create(cityName);

                    _cityRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"New city '{cityName}' added.");
                    _logger.Debug("Finish create new city method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Creation error", $"City with name '{cityName}' already added.");

                _logger.Warning($"City name '{cityName}' already used");
            }
            catch (Exception exc)
            {
                _cityRepository.RollBack();

                _logger.Error($"Exception occurred during the addition of a new city '{cityName}'.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish create new city method.");

            return(result);
        }
コード例 #22
0
        /// <summary>
        /// Delete selected flight
        /// </summary>
        /// <param name="id">Flight identifier.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Delete(Guid id)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start delete flight method.");

            try
            {
                var targetFlight = _flightRepository.FindById(id);
                if (targetFlight != null)
                {
                    _flightRepository.StartTransaction();

                    ManageAircrewByStatus(targetFlight, true);
                    SaveOrDisbandAircrew(targetFlight, true);

                    _flightRepository.Delete(targetFlight);

                    _flightRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"Flight with id: {id}, has been deleted.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Finding error", "Flight is not found.");

                _logger.Warning($"Flight (id: {id}) was not found.");
            }
            catch (Exception exc)
            {
                _flightRepository.RollBack();

                _logger.Error($"Exception occurred during the deletting of a  flight, id: {id}.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish delete flight method.");

            return(result);
        }
コード例 #23
0
        /// <summary>
        /// Delete flight request by identifier.
        /// </summary>
        /// <param name="id">Flight request identifier.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Delete(Guid id)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start delete request message method.");

            try
            {
                var request = _flightRequestRepository.FindById(id);

                if (request != null)
                {
                    _flightRequestRepository.StartTransaction();

                    _flightRequestRepository.Delete(request);

                    _flightRequestRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"Flight request (id: {id}) has been deleted.");
                    _logger.Debug("Finish delete request message method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Deleting error", "Flight request is not found.");

                _logger.Warning($"Request (id: {id}) was not found.");
            }
            catch (Exception exc)
            {
                _flightRequestRepository.RollBack();

                _logger.Error($"Exception occurred during the deleting of a flight request.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish delete request message method.");

            return(result);
        }
コード例 #24
0
        /// <summary>
        /// Delete city by identifier.
        /// </summary>
        /// <param name="id">City identifier</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Delete(Guid id)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start delete city method.");

            try
            {
                var cityToDelete = _cityRepository.FindById(id);

                if (cityToDelete != null)
                {
                    _cityRepository.StartTransaction();

                    _cityRepository.Delete(cityToDelete);

                    _cityRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"City '{cityToDelete.Name}' has been deleted.");
                    _logger.Debug("Finish delete city method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Deleting error", "City is not found.");

                _logger.Warning($"City (id: {id}) was not found.");
            }
            catch (Exception exc)
            {
                _cityRepository.RollBack();

                _logger.Error($"Exception occurred during the deletting of a city.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish delete city method.");

            return(result);
        }
コード例 #25
0
        /// <summary>
        /// Update city.
        /// </summary>
        /// <param name="city">New city data.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Update(CityDto city)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start city update method.");

            try
            {
                var cityToUpdate = _cityRepository.FindById(city.Id);

                if (cityToUpdate != null)
                {
                    _cityRepository.StartTransaction();

                    cityToUpdate.Name = city.Name;

                    _cityRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"City '{cityToUpdate.Name}' has been chanched to '{city.Name}'");
                    _logger.Debug("Finish city update method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Updating error", "City is not found.");

                _logger.Warning($"City (id: {city.Id}) was not found");
            }
            catch (Exception exc)
            {
                _cityRepository.RollBack();

                _logger.Error($"Exception occurred during the updating of a city.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish city update method.");

            return(result);
        }
コード例 #26
0
        public ServiceAnswer<string> Login(string login, string password)
        {
            var res = new ServiceAnswer<string>();
            try
            {
                var token = UserContext.Login(login, password);
                res.Data = token;
                res.CallResult = CallResult.Ok;

            }
            catch (Exception ex)
            {
                res.ErrorText = ex.Message;
                res.ErrorType = ex.GetType().FullName;
                res.CallResult = CallResult.ExceptionOccured;
            }
            return res;
        }
コード例 #27
0
        /// <summary>
        /// Create profession.
        /// </summary>
        /// <param name="professionName">Profession name.</param>
        /// <returns>Service answer that contain: success/failure execution and error list of method.</returns>
        public ServiceAnswer Create(string professionName)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start create profession method.");

            try
            {
                var isUniqueName = IsUniqueName(professionName);
                if (isUniqueName)
                {
                    _professionRepository.StartTransaction();

                    _professionRepository.Create(professionName);

                    _professionRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"New profession {professionName} added.");
                    _logger.Debug("Finish create profession method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Creation error", "Profession with this name already added.");

                _logger.Warning($"Profession name {professionName} alredy used.");
            }
            catch (Exception exc)
            {
                _professionRepository.RollBack();

                _logger.Error($"Exception occurred during the creating  profession.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish create profession method.");

            return(result);
        }
コード例 #28
0
        /// <summary>
        /// Deletr profession.
        /// </summary>
        /// <param name="id">Profession identifier.</param>
        /// <returns>Service answer that contain: success/failure execution and error list of method.</returns>
        public ServiceAnswer Delete(Guid id)
        {
            var result = new ServiceAnswer();

            _logger.Debug("Start delete profession method.");

            try
            {
                var deletedProfession = _professionRepository.FindById(id);
                if (deletedProfession != null)
                {
                    _professionRepository.StartTransaction();

                    _professionRepository.Delete(deletedProfession);

                    _professionRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"Profession (id: {id}) has been deleted.");
                    _logger.Debug("Finish delete profession method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Deletting error", "Profession was not found.");

                _logger.Warning($"Profession (id: {id}) was not found.");
            }
            catch (Exception exc)
            {
                _professionRepository.RollBack();

                _logger.Error($"Exception occurred during the deleting  profession, id: {id}.\r\nException: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish delete profession method.");

            return(result);
        }
コード例 #29
0
        public ServiceAnswer<bool> Authorize(string token, string entityID)
        {
            var res = new ServiceAnswer<bool>();
            try
            {
                Guid calleeID = Guid.Parse(token);
                Guid objectID = Guid.Parse(entityID);
                res.Data = UserContext.Authorize(calleeID, objectID);
                res.CallResult = CallResult.Ok;

            }
            catch (Exception ex)
            {
                res.ErrorText = ex.Message;
                res.ErrorType = ex.GetType().FullName;
                res.CallResult = CallResult.ExceptionOccured;
            }
            return res;
        }
コード例 #30
0
        /// <summary>
        /// Check at not equality and  existing at system required cities. Return found cities.
        /// </summary>
        /// <param name="result">Service answer, need for creation chain of checks.</param>
        /// <param name="idFromCity">From city identifier.</param>
        /// <param name="idToCity">To city identifier.</param>
        /// <returns>Boolean result of cheking.</returns>
        private IEnumerable <City> GetCities(ServiceAnswer result, Guid idFromCity, Guid idToCity)
        {
            if (result.Status == AnswerStatus.Failure)
            {
                return(new List <City>());
            }

            var cities = _cityRepository.GetAll().Where(x => x.Id.Equals(idFromCity) || x.Id.Equals(idToCity)).ToList();

            if (cities.Count() != 2)
            {
                result.Status = AnswerStatus.Failure;
                result.Errors.Add("City error", "One of the cities is not found or you selected one same city twice.");

                _logger.Warning($"One of the cities is not found or one same city twice. Cities id:\r\n {idFromCity}\r\n {idToCity}");

                return(new List <City>());
            }

            return(cities);
        }
コード例 #31
0
        /// <summary>
        /// Set new or edit existing aircrew of flight.
        /// </summary>
        /// <param name="result">Service answer, need for creation chain of checks.</param>
        /// <param name="flight">Flight that updating.</param>
        /// <param name="members">List of aircrew members identifiers.</param>
        /// <returns>Boolean result of success setting new aircrew.</returns>
        private bool SetAircrew(ServiceAnswer result, Flight flight, IEnumerable <Guid> members)
        {
            if (result.Status == AnswerStatus.Failure)
            {
                return(false);
            }

            var newMembers = GetNewMembers(flight, members);

            try {
                var aircrewMembers = _aircrewMemberRepository.GetAll()
                                     .Where(x => x.Status == AircrewMemberStatus.Available)
                                     .Where(x => newMembers.Contains(x.Id))
                                     .ToList();

                if (newMembers.Count() != aircrewMembers.Count())
                {
                    result.Status = AnswerStatus.Failure;
                    result.Errors.Add("Finding error", "Some of the aircrew member are not found or unawailable.");

                    _logger.Warning("Not all new aircrew was find in system.");

                    return(false);
                }

                _flightRepository.AddAircrewMembers(flight, aircrewMembers);
                ManageAircrewByStatus(flight);
            } catch (Exception exc)
            {
                _logger.Error($"Exception occurred during the changing new aircrew.\r\n Exception: {exc.ToString()}");

                return(false);
            }

            return(true);
        }
コード例 #32
0
        /// <summary>
        /// Create ne flight.
        /// </summary>
        /// <param name="flight">flight data.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer Crete(FlightDto flight)
        {
            var result = new ServiceAnswer()
            {
                Status = AnswerStatus.Success
            };

            _logger.Debug("Start create new flight method.");

            try
            {
                if (!CheckNumber(result, flight.Number))
                {
                    _logger.Debug("Finish create new flight method.");

                    return(result);
                }
                ;

                if (!CheckDate(result, flight.DepartureDate, flight.ArrivalDate))
                {
                    _logger.Debug("Finish create new flight method.");

                    return(result);
                }
                ;

                if (!CheckExistencePilot(result, flight.AircrewMembers.Select(x => x.Id)))
                {
                    _logger.Debug("Finish create new flight method.");

                    return(result);
                }

                var cities = GetCities(result, flight.From.Id, flight.To.Id);
                if (cities.Count() == 0)
                {
                    _logger.Debug("Finish create new flight method.");

                    return(result);
                }
                ;

                _flightRepository.StartTransaction();

                var newFligth = _flightRepository.Crete(flight.Number,
                                                        cities.First(x => x.Id == flight.From.Id),
                                                        cities.First(x => x.Id == flight.To.Id),
                                                        flight.DepartureDate,
                                                        flight.ArrivalDate,
                                                        flight.Status);


                if (!SetAircrew(result, newFligth, flight.AircrewMembers.Select(x => x.Id)))
                {
                    _flightRepository.RollBack();

                    _logger.Debug("Finish create new flight method.");

                    return(result);
                }

                _flightRepository.Commit();

                result.Status = AnswerStatus.Success;

                _logger.Info($"Added new flight.\r\n {newFligth.ToString()}");
                _logger.Debug("Finish create new flight method.");

                return(result);
            }
            catch (Exception exc)
            {
                _flightRepository.RollBack();

                _logger.Error($"Exception occurred during the addition of a new flight.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finish create new flight method.");

            return(result);
        }
コード例 #33
0
        /// <summary>
        /// Update existing flight.
        /// </summary>
        /// <param name="updatedFlight">New flight data.</param>
        /// <returns>Service answer that contain success/failure execution and error list of method.</returns>
        public ServiceAnswer UpdateFlight(FlightDto updatedFlight)
        {
            var result = new ServiceAnswer()
            {
                Status = AnswerStatus.Success
            };

            _logger.Debug("Start update flight method.");

            try
            {
                var originalFlight = _flightRepository.FindById(updatedFlight.Id);
                if (originalFlight != null)
                {
                    if (originalFlight.Number == updatedFlight.Number)
                    {
                    }
                    else if (!CheckNumber(result, updatedFlight.Number))
                    {
                        _logger.Debug("Finidh update flight method.");

                        return(result);
                    }
                    ;

                    if (!CheckDate(result, updatedFlight.DepartureDate, updatedFlight.ArrivalDate, false))
                    {
                        _logger.Debug("Finidh update flight method.");

                        return(result);
                    }
                    ;

                    if (!CheckExistencePilot(result, updatedFlight.AircrewMembers.Select(x => x.Id)))
                    {
                        _logger.Debug("Finidh update flight method.");

                        return(result);
                    }

                    var cities = GetCities(result, updatedFlight.From.Id, updatedFlight.To.Id);
                    if (cities.Count() == 0)
                    {
                        _logger.Debug("Finidh update flight method.");

                        return(result);
                    }
                    ;

                    _flightRepository.StartTransaction();

                    SetFlightData(originalFlight, updatedFlight, cities);

                    if (!SetAircrew(result, originalFlight, updatedFlight.AircrewMembers.Select(x => x.Id)))
                    {
                        _flightRepository.RollBack();

                        _logger.Debug("Finidh update flight method.");

                        return(result);
                    }

                    SaveOrDisbandAircrew(originalFlight);

                    _flightRepository.Commit();

                    result.Status = AnswerStatus.Success;

                    _logger.Info($"Flight have been updated.\r\n {originalFlight.ToString()}");
                    _logger.Debug("Finidh update flight method.");

                    return(result);
                }

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Finding error", "Flight is not found.");

                _logger.Warning($"Flight (id: {updatedFlight.Id}) was not found.");
            }
            catch (Exception exc)
            {
                _flightRepository.RollBack();

                _logger.Error($"Exception occurred during the update of a flight, id: {updatedFlight.Id}.\r\n Exception: {exc.ToString()}");

                result.Status = AnswerStatus.Failure;
                result.Errors.Add("Service error", "Some trouble with getting data. Try Later.");
            }

            _logger.Debug("Finidh update flight method.");

            return(result);
        }
コード例 #34
0
 public AnswerController(IServiceAnswer serviceAnswer)
 {
     this.serviceAnswer = (ServiceAnswer)serviceAnswer;
 }