コード例 #1
0
        public ExtraService FindOne(int id)
        {
            if (id < 0)
            {
                return(null);
            }
            SqlConnection connection = DatabaseConnection.GetConnection();
            string        select     = @"dbo.[FindService]";

            connection.Open();
            using (var cmd = new SqlCommand(select, connection))
            {
                var param = cmd.CreateParameter();
                param.ParameterName = "id";
                param.Value         = id;
                cmd.Parameters.Add(param);

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        ExtraService ExtraService = new ExtraService(int.Parse(reader["id"].ToString()), (string)reader["type"].ToString(), (float)reader["price"]);
                        connection.Close();
                        return(ExtraService);
                    }
                    else
                    {
                        connection.Close();
                        return(null);
                    }
                }
            }
        }
コード例 #2
0
        public void AddExtraToCar_WhenValidParametersArePassedAndExtraDoesNotExists()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var carServiceMock = new Mock <ICarService>();

            string extraName = "testExtra";
            var    carId     = 1;
            var    car       = new Car()
            {
                Id = carId
            };
            var carExtra   = new CarsExtras();
            var listOfCars = new List <Car>()
            {
                car
            };
            var listCarsExtras = new List <CarsExtras>();
            var listExtras     = new List <Extra>();

            carServiceMock.Setup(c => c.GetCar(It.IsAny <int>())).Returns(car);
            unitOfWorkMock.Setup(u => u.GetRepository <Car>().All()).Returns(listOfCars.AsQueryable());
            unitOfWorkMock.Setup(u => u.GetRepository <CarsExtras>().All()).Returns(listCarsExtras.AsQueryable());
            unitOfWorkMock.Setup(u => u.GetRepository <Extra>().All()).Returns(listExtras.AsQueryable());

            var sut = new ExtraService(unitOfWorkMock.Object);

            // Act
            sut.AddExtraToCar(carId, extraName);

            // Assert
            unitOfWorkMock.Verify(u => u.GetRepository <CarsExtras>().Add(It.IsAny <CarsExtras>()), Times.Once);

            unitOfWorkMock.Verify(c => c.SaveChanges(), Times.Exactly(2));
        }
        private static Entity PrepareBookingExtraService(Booking bookinginfo, ExtraService extraService, Guid bookingId, ITracingService trace)
        {
            trace.Trace("Preparing Booking Transfer information - Start");
            var extraServiceEntity = new Entity(EntityName.BookingExtraService);

            if (!string.IsNullOrWhiteSpace(extraService.ExtraServiceCode))
            {
                extraServiceEntity[Attributes.BookingExtraService.ExtraServiceCode] = extraService.ExtraServiceCode;
            }

            SetNameFor(extraService, bookinginfo, extraServiceEntity);

            extraServiceEntity[Attributes.BookingExtraService.Order] = extraService.Order;
            if (!string.IsNullOrWhiteSpace(extraService.StartDate))
            {
                extraServiceEntity[Attributes.BookingExtraService.StartDateAndTime] = DateTime.Parse(extraService.StartDate);
            }
            if (!string.IsNullOrWhiteSpace(extraService.EndDate))
            {
                extraServiceEntity[Attributes.BookingExtraService.EndDateTime] = DateTime.Parse(extraService.EndDate);
            }


            extraServiceEntity[Attributes.BookingExtraService.Participants] = BookingHelper.PrepareTravelParticipantsInfoForChildRecords(bookinginfo.TravelParticipant, trace, extraService.TravelParticipantAssignment);

            extraServiceEntity[Attributes.BookingExtraService.BookingId] = new EntityReference(EntityName.Booking, bookingId);
            extraServiceEntity[Attributes.Booking.Remarks] = RemarksHelper.GetRemarksTextFromPayload(extraService.Remark);
            extraServiceEntity[Attributes.BookingExtraService.ExtraServiceType]        = CommonXrm.GetExtraServiceType(extraService.ExtraServiceType);
            extraServiceEntity[Attributes.BookingExtraService.ExtraServiceDescription] = (!string.IsNullOrWhiteSpace(extraService.ExtraServiceDescription)) ?
                                                                                         extraService.ExtraServiceDescription : string.Empty;
            trace.Trace("Preparing Booking Transfer information - End");

            return(extraServiceEntity);
        }
コード例 #4
0
        public void ThrowArgumentException_WhenInvalidParametersArePassed()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var carServiceMock = new Mock <ICarService>();

            string extraName = "testExtra";
            var    carId     = 1;
            var    car       = new Car()
            {
                Id = carId
            };
            var carExtra   = new CarsExtras();
            var listOfCars = new List <Car>()
            {
                car
            };
            var listCarsExtras = new List <CarsExtras>();
            var listExtras     = new List <Extra>();

            carServiceMock.Setup(c => c.GetCar(It.IsAny <int>())).Returns(car);
            unitOfWorkMock.Setup(u => u.GetRepository <Car>().All()).Returns(listOfCars.AsQueryable());
            unitOfWorkMock.Setup(u => u.GetRepository <CarsExtras>().All()).Returns(listCarsExtras.AsQueryable());
            unitOfWorkMock.Setup(u => u.GetRepository <Extra>().All()).Returns(listExtras.AsQueryable());

            var invalidCarId = -1;
            var sut          = new ExtraService(unitOfWorkMock.Object);

            // Act   && Assert
            Assert.ThrowsException <ArgumentException>(() => sut.AddExtraToCar(invalidCarId, extraName));
        }
コード例 #5
0
 public ExtraServiceModel(ExtraService service)
 {
     id                = service.id;
     name              = service.name;
     subscFee          = service.subscFee;
     description       = service.description;
     CanConnectThisSer = service.CanConnectThisSer;
 }
コード例 #6
0
/*        public PhysicalPersonModel GetItemPhysicalPerson(int id)
 *      {
 *          PhysicalPerson c = db.PhysicalPerson.ToList().Where(i => i.id == id).FirstOrDefault();
 *          return new PhysicalPersonModel() { id = c.id, dateOfBirth =c.dateOfBirth, name=c.name, numberPassport =c.numberPassport, surname =c.surname };
 *      }
 *      public LegalPersonModel GetItemLegalPerson(int id)
 *      {
 *          LegalPerson c = db.LegalPerson.ToList().Where(i => i.id == id).FirstOrDefault();
 *          return new LegalPersonModel() { name =c.name, id = c.id, ITN = c.ITN, legalAdress =c.legalAdress, startDate =c.startDate };
 *      }*/
        public ExtraServiceModel GetItemExtraService(int id)
        {
            ExtraService c = db.ExtraService.ToList().Where(i => i.id == id).FirstOrDefault();

            return(new ExtraServiceModel()
            {
                CanConnectThisSer = c.CanConnectThisSer, id = c.id, name = c.name, description = c.description, subscFee = c.subscFee
            });
        }
コード例 #7
0
        public void Update(ExtraService service)
        {
            var context = new HotelEntities();

            var oldService = context.ServiciiSuplimentare.First(i => i.Id_ServiciiSuplimentare == service.Id);

            oldService.Price = service.Price;
            oldService.Type  = service.Type;

            context.SaveChanges();
        }
コード例 #8
0
        public async Task <IActionResult> CreateNewService([FromBody] ExtraService service)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _context.ExtraServices.Add(service);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExtraService", new { id = service.Id }, service));
        }
コード例 #9
0
        public void Add(ExtraService service)
        {
            var newService = new ServiciiSuplimentare();

            newService.Price = service.Price;
            newService.Type  = service.Type;

            var context = new HotelEntities();

            context.ServiciiSuplimentare.Add(newService);
            context.SaveChanges();
        }
コード例 #10
0
        public void ThrowArgumentException_WhenCarAlreadyContainsExtra()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var carServiceMock = new Mock <ICarService>();

            string extraName = "testExtra";
            var    extraId   = 1;
            var    carId     = 1;

            var carExtra = new CarsExtras()
            {
                CarId = carId, ExtraId = extraId
            };

            var extra = new Extra()
            {
                Id = extraId, Name = extraName
            };
            var car = new Car()
            {
                Id = carId
            };

            car.CarsExtras.Add(carExtra);
            extra.CarsExtras.Add(carExtra);
            carExtra.Car   = car;
            carExtra.Extra = extra;

            var listOfCars = new List <Car>()
            {
                car
            };
            var listExtras = new List <Extra>()
            {
                extra
            };
            var listCarsExtras = new List <CarsExtras>()
            {
                carExtra
            };

            carServiceMock.Setup(c => c.GetCar(It.IsAny <int>())).Returns(car);
            unitOfWorkMock.Setup(u => u.GetRepository <Car>().All()).Returns(listOfCars.AsQueryable());
            unitOfWorkMock.Setup(u => u.GetRepository <CarsExtras>().All()).Returns(listCarsExtras.AsQueryable());
            unitOfWorkMock.Setup(u => u.GetRepository <Extra>().All()).Returns(listExtras.AsQueryable());

            var sut = new ExtraService(unitOfWorkMock.Object);

            // Act   && Assert
            Assert.ThrowsException <ArgumentException>(() => sut.AddExtraToCar(carId, extraName));
        }
コード例 #11
0
        public ExtraService Delete(int id)
        {
            ExtraService  ExtraService = FindOne(id);
            SqlConnection connection   = DatabaseConnection.GetConnection();

            connection.Open();
            if (ExtraService == null)
            {
                connection.Close();
                return(null);
            }

            connection.Close();
            return(ExtraService);
        }
コード例 #12
0
        public void SelectService(object param)
        {
            var temp = param as ExtraService;

            var s = new ExtraService()
            {
                Id    = temp.Id,
                Type  = temp.Type,
                Price = temp.Price
            };

            DataManager.Instance.CurrentServices.Add(s);
            viewModel.TotalInt += temp.Price;
            viewModel.ExtraServicesList.Remove(temp);
        }
コード例 #13
0
        public void ReturnAListOfExtras_WhenValidParametersArePassed()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var carServiceMock = new Mock <ICarService>();

            string extraName = "testExtra";
            var    extraId   = 1;
            var    carId     = 1;

            var carExtra = new CarsExtras()
            {
                CarId = carId, ExtraId = extraId
            };
            var extra = new Extra()
            {
                Id = extraId, Name = extraName
            };
            var car = new Car()
            {
                Id = carId
            };

            car.CarsExtras.Add(carExtra);
            extra.CarsExtras.Add(carExtra);
            carExtra.Car   = car;
            carExtra.Extra = extra;
            var listOfCars = new List <Car>()
            {
                car
            };
            var listExtras = new List <Extra>()
            {
                extra
            };

            unitOfWorkMock.Setup(u => u.GetRepository <Car>().All()).Returns(listOfCars.AsQueryable());

            var sut = new ExtraService(unitOfWorkMock.Object);
            // Act
            var actual = sut.GetExtrasForCar(carId);

            // Assert
            Assert.AreEqual(listExtras.First().Id, actual.First().Id);
        }
コード例 #14
0
        public void AddExtra_WhenValidParametersArePassed()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();

            string extraName = "testExtra";

            unitOfWorkMock.Setup(u => u.GetRepository <Extra>().All()).Returns(new List <Extra>().AsQueryable());

            var sut = new ExtraService(unitOfWorkMock.Object);

            // Act
            sut.CreateExtra(extraName);

            // Assert
            unitOfWorkMock.Verify(u => u.GetRepository <Extra>().Add(It.IsAny <Extra>()), Times.Once);

            unitOfWorkMock.Verify(c => c.SaveChanges(), Times.Once);
        }
コード例 #15
0
        public void Add(object param)
        {
            var tuple = param as Tuple <string, string>;

            string type  = tuple.Item1;
            int    price = int.Parse(tuple.Item2);

            if (String.IsNullOrEmpty(type))
            {
                return;
            }

            ExtraService service = new ExtraService()
            {
                Type  = type,
                Price = price
            };

            extraServicesDAL.Add(service);
        }
コード例 #16
0
        public List <ExtraService> GetAll()
        {
            List <ExtraService> extraServices = new List <ExtraService>();
            string        procedure           = @"dbo.[GetAllExtraServices]";
            SqlConnection connection          = DatabaseConnection.GetConnection();

            connection.Open();
            using (var cmd = new SqlCommand(procedure, connection))
            {
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ExtraService extraService = new ExtraService(int.Parse(reader["id"].ToString()), (string)reader["type"].ToString(), float.Parse(reader["price"].ToString()));
                        extraServices.Add(extraService);
                    }
                    connection.Close();
                    return(extraServices);
                }
            }
        }
コード例 #17
0
        public ObservableCollection <ExtraService> GetExtraServices()
        {
            ObservableCollection <ExtraService> result = new ObservableCollection <ExtraService>();
            var context = new HotelEntities();

            foreach (var extraService in context.ServiciiSuplimentare)
            {
                var newExtraService = new ExtraService()
                {
                    Id    = extraService.Id_ServiciiSuplimentare,
                    Price = extraService.Price,
                    Type  = extraService.Type
                };

                if (!extraService.Deleted)
                {
                    result.Add(newExtraService);
                }
            }
            return(result);
        }
コード例 #18
0
        public void Update(object param)
        {
            var tuple = param as Tuple <string, string>;

            string type  = tuple.Item1;
            int    price = int.Parse(tuple.Item2);

            if (String.IsNullOrEmpty(type))
            {
                return;
            }

            ExtraService service = new ExtraService()
            {
                Id    = DataManager.Instance.SelectedExtraService.Id,
                Type  = type,
                Price = price
            };

            extraServicesDAL.Update(service);
        }
コード例 #19
0
        public ExtraService Update(int id, ExtraService ExtraService)
        {
            ExtraService clon = ExtraService;

            if (id < 0 || ExtraService == null)
            {
                return(null);
            }
            SqlConnection connection = DatabaseConnection.GetConnection();

            connection.Open();
            string select = @"dbo.[UpdateService]";

            using (var cmd = new SqlCommand(select, connection))
            {
                var param1 = cmd.CreateParameter();
                param1.ParameterName = "@type";
                param1.Value         = ExtraService.Type;

                var param3 = cmd.CreateParameter();
                param3.ParameterName = "@price";
                param3.Value         = ExtraService.Price;

                cmd.Parameters.Add(param1);
                cmd.Parameters.Add(param3);
                int affectedRows = cmd.ExecuteNonQuery();


                if (affectedRows != 0)
                {
                    connection.Close();
                    return(clon);
                }
                else
                {
                    connection.Close();
                    return(null);
                }
            }
        }
コード例 #20
0
        public ExtraService Save(ExtraService ExtraService)
        {
            SqlConnection connection = DatabaseConnection.GetConnection();

            connection.Open();
            var select = @"dbo.[CreateService]";

            using (var cmd = new SqlCommand(select, connection))
            {
                var param1 = cmd.CreateParameter();
                param1.ParameterName = "@id";
                param1.Value         = ExtraService.Id;

                var param2 = cmd.CreateParameter();
                param2.ParameterName = "@type";
                param2.Value         = ExtraService.Type;

                var param4 = cmd.CreateParameter();
                param4.ParameterName = "@price";
                param4.Value         = ExtraService.Price;


                cmd.Parameters.Add(param1);
                cmd.Parameters.Add(param2);
                cmd.Parameters.Add(param4);

                int affectedRows = cmd.ExecuteNonQuery();
                if (affectedRows != 0)
                {
                    ExtraService extraService = new ExtraService(ExtraService.Id, ExtraService.Type, ExtraService.Price);
                    connection.Close();
                    return(extraService);
                }
                else
                {
                    connection.Close();
                    return(null);
                }
            }
        }
コード例 #21
0
        public void ThrowArgumentException_WhenExtraAlreadyExists()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();

            string extraName     = "testExtra";
            var    existingExtra = new Extra()
            {
                Name = "testExtra"
            };
            var listOfExtras = new List <Extra>()
            {
                existingExtra
            };

            unitOfWorkMock.Setup(u => u.GetRepository <Extra>().All()).Returns(listOfExtras.AsQueryable());

            var sut = new ExtraService(unitOfWorkMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentException>(() => sut.CreateExtra(extraName));
        }
コード例 #22
0
        public async Task <IActionResult> UpdateService([FromRoute] int id, [FromBody] ExtraService service)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var item = _context.ExtraServices.Find(id);

            if (item == null)
            {
                return(NotFound());
            }
            //блок перезаписи данных
            item.Name              = service.Name;
            item.SubscFee          = service.SubscFee;
            item.Description       = service.Description;
            item.CanConnectThisSer = service.CanConnectThisSer;
            _context.ExtraServices.Update(item);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #23
0
        public void Service(Car car)
        {
            //Some services need to be done explicitly and in order choosen by the garage
            Console.WriteLine("servicing tire pressure..");
            Console.WriteLine("servicing oil..");


            //Some services can be done 'indirectly or forwarded to external parties' but still in order choosen by the garage
            //Performing Extra Service, but which? The garage does not need to control that
            //if (ExtraService != null)
            //{
            //    ExtraService(car);
            //}
            //Line below ias same as if-statement above, just a null check
            ExtraService?.Invoke(car);

            Console.WriteLine("cleaning interior");

            //A window servicing company could actually travel in real life to the garage and perform services on site
            WindowService?.Invoke(car);

            //As an ending service: the car needs to be washed
            Console.WriteLine("washing car");
        }
コード例 #24
0
        public void ThrowArgumentException_WhenInvalidIdIsPassed()
        {
            // Arrange
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var carServiceMock = new Mock <ICarService>();

            var invalidId = -1;
            var car       = new Car()
            {
                Id = 1
            };
            var list = new List <Car>()
            {
                car
            };

            carServiceMock.Setup(c => c.GetCar(It.IsAny <int>())).Returns(car);
            unitOfWorkMock.Setup(u => u.GetRepository <Car>().All()).Returns(list.AsQueryable());

            var sut = new ExtraService(unitOfWorkMock.Object);

            // Act   && Assert
            Assert.ThrowsException <ArgumentException>(() => sut.GetExtrasForCar(invalidId));
        }
        private static void SetNameFor(ExtraService extraService, Booking bookinginfo, Entity extraServiceEntity)
        {
            var bookingNumber = bookinginfo.BookingIdentifier.BookingNumber;

            extraServiceEntity[Attributes.BookingExtraService.Name] = $"{extraService.ExtraServiceDescription} - {bookingNumber}";
        }
コード例 #26
0
        private List <ShippingOption> InterpretShippingOptions(IntlRateV2Response response, decimal minimumShippingRate)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (response.Error != null)
            {
                return(new List <ShippingOption> {
                    new ShippingOption {
                        Name = response.Error.Description
                    }
                });
            }

            if (minimumShippingRate < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumShippingRate), minimumShippingRate, "minimumShippingRate must be greater than zero");
            }

            string[] carrierServicesOffered   = _uspsSettings.InternationalServicesSelected.Split(',');
            decimal  additionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge;
            var      options = new List <ShippingOption>();

            foreach (SeeSharpShip.Models.Usps.International.Response.Package package in response.Packages)
            {
                // indicate a package error if there is one and skip to the next package
                if (package.Error != null)
                {
                    options.Add(new ShippingOption {
                        Name = package.Error.Description
                    });
                    continue;
                }

                foreach (Service service in package.Services)
                {
                    // service doesn't match one that is enabled, move on to the next one
                    if (!carrierServicesOffered.Contains(service.Id))
                    {
                        continue;
                    }

                    string serviceName = GetModifiedServiceName(service.SvcDescription);

                    ExtraService   insurance      = service.ExtraServices?.FirstOrDefault(s => s.ServiceId == "1");
                    decimal        rate           = service.Postage + (insurance?.Price ?? 0) + additionalHandlingCharge;
                    ShippingOption shippingOption = options.Find(o => o.Name == serviceName);

                    // Use min shipping amount if rate is less than minimum
                    rate = rate < minimumShippingRate ? minimumShippingRate : rate;

                    if (shippingOption == null)
                    {
                        // service doesn't exist yet, so create a new one
                        shippingOption = new ShippingOption {
                            Name = serviceName,
                            Rate = rate,
                        };

                        options.Add(shippingOption);
                    }
                    else
                    {
                        // service is already in the list, so let's add the current postage rate to it
                        shippingOption.Rate += rate;
                    }
                }
            }

            return(options);
        }