Exemplo n.º 1
0
        public void AddGuest_Success_CallsRepositoryWithCorrectParameters()
        {
            //Arrenge
            var guestViewModel = new GuestViewModel()
            {
                FirstName = "Misha",
                LastName  = "Gonchak",
                City      = "Rakovets"
            };
            var guestRepoMock = new Mock <IGuestRepository>();

            guestRepoMock.Setup(r => r.AddGuest(It.IsAny <Guest>())).Returns(new Guest());
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });
            IMapper mapper       = mappingConfig.CreateMapper();
            var     guestService = new GuestService(mapper, guestRepoMock.Object);

            //Act
            var result = guestService.AddGuest(guestViewModel);

            //Assert
            guestRepoMock.Verify(r => r.AddGuest(It.Is <Guest>(g => g.FirstName == guestViewModel.FirstName)), Times.Once);
        }
        public async Task <ActionResult> NewReservation(AdminNewReservation Data)
        {
            int   result;
            Guest guest = new Guest {
                GuestCode    = 0,
                GuestName    = Data.GuestName,
                NationalID   = Data.NationalID,
                Nationality  = Data.Nationality,
                PhoneNumber  = Data.PhoneNumber,
                Gender       = Data.Gender,
                GuestAddress = Data.GuestAddress
            };

            if (Data.GuestCode != 0)
            {
                guest.GuestCode = Data.GuestCode;
                result          = await GuestStore.UpdateGuest(guest.GuestCode, guest);
            }
            else
            {
                result = await GuestStore.AddGuest(guest);
            }
            guest = GuestStore.GetGuestByNationalId(Data.NationalID);
            RoomReservation roomReservation = new RoomReservation {
                StartDate = Data.StartDate,
                EndDate   = Data.EndDate,
                RoomID    = Data.RoomID,
                GuestID   = guest.GuestCode
            };

            result = await RoomReservationstore.CreatNewReservation(roomReservation);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        private void AddGuest(object sender, RoutedEventArgs e)
        {
            try
            {
                var townName = this.Town.Text.ToString();
                var student  = RoomService.GetStudentByRoomAndName(
                    Rooms.SelectedItem.ToString(), Student.SelectedItem.ToString());

                Guest guest = new Guest
                {
                    FirstName      = this.FirstName.Text ?? "",
                    MiddleName     = this.MiddleName.Text ?? "",
                    LastName       = this.LastName.Text ?? "",
                    StudentVisited = student,
                    Town           = TownService.GetTownByName(townName)
                };
                GuestService.AddGuest(guest);
                MessageBox.Show($"Added guest {this.FirstName.Text} {this.LastName.Text} to {student.FullName}", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                this.Content = new AddGuestUserControl();
            }
            catch (Exception)
            {
                MessageBox.Show($"You need to fill all fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 4
0
        public void AddGuest_IsNotNull()
        {
            //Arrenge
            var guestViewModel = new GuestViewModel();
            var guestRepoMock  = new Mock <IGuestRepository>();

            guestRepoMock.Setup(r => r.AddGuest(It.IsAny <Guest>())).Returns(new Guest());
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });
            IMapper mapper       = mappingConfig.CreateMapper();
            var     guestService = new GuestService(mapper, guestRepoMock.Object);

            //Act
            var result = guestService.AddGuest(guestViewModel);

            //Assert
            Assert.IsNotNull(result);
        }
        public async Task <ActionResult> Register(RegisterUserGuest Data)
        {
            User  user;
            Guest guest;

            user = UserStore.checkEmail(Data.Email);
            if (user == null)
            {
                guest = GuestStore.GetGuestByNationalId(Data.NationalID);
                if (guest == null)
                {
                    int result = await UserStore.AddUser(user = new User {
                        UserEmail    = Data.Email,
                        UserPassword = Data.PassWord,
                        RoleId       = 2
                    });

                    if (result != 0)
                    {
                        int result2 = await GuestStore.AddGuest(guest = new Guest {
                            UserId       = user.UserCode,
                            GuestName    = Data.GuestName,
                            PhoneNumber  = Data.PhoneNumber,
                            NationalID   = Data.NationalID,
                            Nationality  = Data.Nationality,
                            Gender       = Data.Gender,
                            GuestAddress = Data.GuestAddress
                        });

                        if (result2 != 0)
                        {
                            return(View("Index"));
                        }
                    }
                }
            }

            return(View("LogIn"));
        }
Exemplo n.º 6
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            GuestService.AddGuest();
            return(View());
        }
Exemplo n.º 7
0
 /// <summary>
 /// 增加客人信息
 /// </summary>
 /// <param name="guest"></param>
 /// <returns></returns>
 public static Guest AddGuest(Guest guest)
 {
     return(GuestService.AddGuest(guest));
 }