Exemplo n.º 1
0
        public Task <BaseResult> DeleteRelation(Vehicle v, VehicleToEmployeeRelation r)
        {
            var fleeter = new FleeterServiceClient();

            fleeter.Open();
            return(fleeter.DeleteEmployeeRelationAsync(v, r));
        }
Exemplo n.º 2
0
        public bool AddVehicleToEmployeeRelation(VehicleToEmployeeRelation relation)
        {
            //if (_vehicleToEmployeeRepository.GetRelationFromRelationId(relation.Id) != null) return false;

            try
            {
                _vehicleToEmployeeRepository.Save(relation);
            }
            catch
            { return(false); }

            return((_vehicleToEmployeeRepository.GetRelationFromRelationId(relation.Id) != null) ? true : false);
        }
Exemplo n.º 3
0
        public BaseResult CreateEmployeeRelation(Vehicle v, VehicleToEmployeeRelation r)
        {
            if (r.EndDate != null && r.StartDate > r.EndDate)
            {
                return(new BaseResult
                {
                    Status = Status.BadRequest,
                    Message = "Startdatum muss vor dem Enddatum liegen"
                });
            }

            try
            {
                var vehicle = _vehicles.FindById(v.Id);

                if (vehicle is null)
                {
                    return(new BaseResult
                    {
                        Status = Status.BadRequest,
                        Message = "Fahrzeug existiert nicht"
                    });
                }

                if (r.StartDate > vehicle.LeasingTo || r.StartDate < vehicle.LeasingFrom || r.EndDate > vehicle.LeasingTo || r.EndDate < vehicle.LeasingFrom)
                {
                    return(new BaseResult
                    {
                        Status = Status.BadRequest,
                        Message = $"Relationen können nur während des Leasingzeitraumes erstellt werden ({vehicle.LeasingFrom} - {vehicle.LeasingTo})"
                    });
                }

                vehicle.AddRelation(r);

                _vehicles.Update(vehicle);

                return(new BaseResult
                {
                    Status = Status.Created
                });
            }
            catch (Exception ex)
            {
                return(new BaseResult
                {
                    Status = Status.InternalServerError,
                    Message = "Verknüpfung konnte nicht erstellt werden:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException?.Message
                });
            }
        }
Exemplo n.º 4
0
        public bool DeleteVehicleToEmployeeRelation(VehicleToEmployeeRelation relation)
        {
            if (_vehicleToEmployeeRepository.GetRelationFromRelationId(relation.Id) == null)
            {
                return(false);
            }

            try
            {
                _vehicleToEmployeeRepository.Delete(relation);
            }
            catch
            { return(false); }

            //return (_vehicleToEmployeeRepository.GetRelationFromRelationId(relation.Id) == null) ? true : false;
            return(true);
        }
Exemplo n.º 5
0
        public BaseResult DeleteEmployeeRelation(Vehicle v, VehicleToEmployeeRelation r)
        {
            try
            {
                var vehicle = _vehicles.FindById(v.Id);

                if (vehicle is null)
                {
                    return(new BaseResult
                    {
                        Status = Status.BadRequest,
                        Message = "Fahrzeug existiert nicht"
                    });
                }

                var wasRemoved = vehicle.RemoveRelation(r);

                if (!wasRemoved)
                {
                    return(new BaseResult
                    {
                        Status = Status.InternalServerError,
                        Message = "Verknüpfung konnte nicht gelöscht werden"
                    });
                }

                _vehicles.Update(vehicle);

                return(new BaseResult
                {
                    Status = Status.Deleted
                });
            }
            catch (Exception ex)
            {
                return(new BaseResult
                {
                    Status = Status.InternalServerError,
                    Message = ex.Message + Environment.NewLine + ex.InnerException?.Message
                });
            }
        }
Exemplo n.º 6
0
 private IEnumerable <(DateTime Month, int Count, decimal Costs)> GetCostsPerVehicle(VehicleToEmployeeRelation vehicleEmployee, Vehicle vehicle)
 {
     for (DateTime i = vehicleEmployee.StartDate; i < (vehicleEmployee?.EndDate ?? DateTime.Now); i = i.AddMonths(1))
     {
         yield return(new DateTime(i.Year, i.Month, 1), 1, vehicle.Insurance / 12 + vehicle.LeasingRate);
     }
 }