Exemple #1
0
        public IActionResult Edit(int id)
        {
            BoatService   service = new BoatService();
            BoatViewModel model   = service.GetBoatInfo(id);

            return(View(model));
        }
Exemple #2
0
 static ServiceLocator()
 {
     AddressService        = new AddressService();
     BoatService           = new BoatService();
     ClubService           = new ClubService();
     UserService           = new UserService();
     EntryService          = new EntryService();
     RaceEventService      = new RaceEventService();
     RegattaService        = new RegattaService();
     SocialEventService    = new SocialEventService();
     TeamService           = new TeamService();
     EmailService          = new EmailService();
     PhoneNumberService    = new PhoneNumberService();
     RegisteredUserService = new RegisteredUserService();
     ResultService         = new ResultService();
     UserRoleService       = new UserRoleService();
     ClubsUsersUserRolesJunctionsService    = new Clubs_Users_UserRoles_JunctionsService();
     RegattasUsersUserRolesJunctionsService = new Regattas_Users_UserRoles_JunctionsService();
     RegisteredUserSocialEventService       = new RegisteredUser_SocialEventService();
     TeamRaceEventService      = new Team_RaceEventService();
     TeamRegisteredUserService = new Team_RegisteredUserService();
     BoatService = new BoatService();
     SocialEventsUsersUserRolesJunctionsService = new SocialEvents_Users_UserRoles_JunctionsService();
     RaceEventsUsersUserRolesJunctionsService   = new RaceEvents_Users_UserRoles_JunctionsService();
     ClubsEmailsService       = new ClubsEmailsService();
     ClubsPhoneNumbersService = new ClubsPhoneNumbersService();
 }
Exemple #3
0
        public ActionResult Edit(int?id)
        {
            if (id == null || id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BoatDTO, BoatEditViewModel>();
            });

            try
            {
                using (var boatService = new BoatService())
                {
                    var boatList = boatService.EagerDisconnectedService.FindBy(x => x.Id == id);
                    if (boatList == null)
                    {
                        return(HttpNotFound());
                    }
                    var boat   = new BoatEditViewModel();
                    var mapper = mapperConfig.CreateMapper();
                    mapper.Map(boatList.First(), boat);
                    return(View(boat));
                }
            }
            catch (Exception e)
            {
                TempData["ResultMessage"] = e.Message;
                return(View("Error"));
            }
        }
Exemple #4
0
        public ActionResult Index()
        {
            var boatList     = new List <BoatIndexViewModel>();
            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BoatDTO, BoatIndexViewModel>();
            });

            using (var boatService = new BoatService())
            {
                try
                {
                    var allBoatsDto = boatService.EagerDisconnectedService.GetAll();
                    if (allBoatsDto == null)
                    {
                        throw new NullReferenceException();
                    }
                    allBoatsDto = allBoatsDto.Where(x => x.Active);
                    if (allBoatsDto.Any())
                    {
                        var mapper = mapperConfig.CreateMapper();
                        mapper.Map(allBoatsDto, boatList);
                        return(View(boatList.OrderBy(b => b.SailNo)));
                    }
                    throw new Exception("Could not find any boats.");
                }
                catch (Exception e)
                {
                    TempData["ResultMessage"] = e.Message;
                    return(View("Error"));
                }
            }
        }
Exemple #5
0
        public IActionResult Product(int boat_id)
        {
            BoatService   service = new BoatService();
            BoatViewModel boat    = service.GetBoatInfo(boat_id);

            return(View(boat));
        }
Exemple #6
0
 public ActionResult Delete(int?id)  //TODO kolla i databas om boat blir Active = false
 {
     if (id == null || id == 0)
     {
         throw new NullReferenceException();
     }
     try
     {
         using (var boatService = new BoatService())
         {
             var foundBoatToDelete = boatService.EagerDisconnectedService.FindBy(x => x.Id == id.Value);
             if (foundBoatToDelete == null)
             {
                 throw new NullReferenceException();
             }
             var arne = foundBoatToDelete.First();
             // boatService.EagerDisconnectedService.Delete(arne);
             //boatService.EagerDisconnectedService.Delete(foundBoatToDelete.First());
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         TempData["ResultMessage"] = e.Message;
         return(View("Error"));
     }
 }
Exemple #7
0
        public async Task <IActionResult> Edit(BoatViewModel model)
        {
            if (ModelState.IsValid)
            {
                BoatService          service   = new BoatService();
                AuthorizationService a_service = new AuthorizationService();
                model.Owner = a_service.GetAccountInfo(User.Identity.Name).Id;
                int code = service.EditBoat(model);
                switch (code)
                {
                case 0: return(RedirectToAction("Index", "User"));

                case 1:
                {
                    ModelState.AddModelError("", "Ошибка при редактировании записи");
                }
                break;
                }
            }
            else
            {
                ModelState.AddModelError("", "Неверное заполнение полей");
            }
            return(RedirectToAction("Edit", "Boat", model));
        }
Exemple #8
0
        public async Task <IActionResult> Delete(int id)
        {
            BoatService service = new BoatService();

            service.DeleteBoat(id);
            return(RedirectToAction("Products", "User"));
        }
Exemple #9
0
        public void AddShouldSetObjectIntoDB_WithHandicap_Test()
        {
            // Arrange
            var boat1 = new Boat
            {
                Active      = true,
                Description = "A boat",
                Entries     = null,
                Handicap    = 10.5,
                Id          = 1,
                Model       = null,
                Name        = "SomeBoat",
                SailNo      = 122
            };
            var boat2 = new Boat
            {
                Active      = true,
                Description = "A boat",
                Entries     = null,
                Handicap    = 2.5,
                Id          = 2,
                Model       = null,
                Name        = "SomeBoat",
                SailNo      = 122
            };

            fakeRepository = new FakeRepository <Boat>();
            boatService    = new BoatService(fakeRepository);
            // Act
            boatService.AddBoat(boat1);
            boatService.AddBoat(boat2);
            // Assert
            fakeRepository.Get(1).Handicap.Should().Be(10.5);
            fakeRepository.Get(2).Handicap.Should().Be(2.5);
        }
Exemple #10
0
 public ActionResult Create(BoatRegistrationViewModel boatRegistrationViewModel) //TODO kolla i databas om det sparas
 {
     try
     {
         BoatDTO boat         = new BoatDTO(boatRegistrationViewModel.SailNo, boatRegistrationViewModel.Name, boatRegistrationViewModel.Type, boatRegistrationViewModel.Handicap);
         var     mapperConfig = new MapperConfiguration(cfg => cfg.CreateMap <BoatRegistrationViewModel, BoatDTO>());
         var     mapper       = mapperConfig.CreateMapper();
         mapper.Map(boatRegistrationViewModel, boat);
         UserDTO user;
         using (var userService = new UserService())
         {
             var loginUser = Session["Login"].ToString();
             user = userService.EagerDisconnectedService.FindBy(u => u.Login == loginUser).First();
         }
         using (var boatService = new BoatService())
         {
             boatService.EagerDisconnectedService.Add(user, boat);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         TempData["ResultMessage"] = e.Message;
         return(View("Error"));
     }
 }
Exemple #11
0
        //TODO fix boatDropDownListViewModel
        public ActionResult DropDownList()
        {
            //ViewBag.BoatId = new SelectList(db.Boats, "Id", "Name");

            var boatList     = new List <BoatDropDownListViewModel>();
            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BoatDTO, BoatDropDownListViewModel>();
            });

            using (var boatService = new BoatService())
            {
                try
                {
                    var allBoatsDto = boatService.EagerDisconnectedService.GetAll().Where(x => x.Active);
                    if (allBoatsDto == null)
                    {
                        throw new NullReferenceException();
                    }
                    var mapper = mapperConfig.CreateMapper();
                    mapper.Map(allBoatsDto, boatList);

                    ViewBag.BoatId = new SelectList(boatList.OrderBy(b => b.FullBoatName), "Id", "FullBoatName");
                    return(View());
                }
                catch (Exception e)
                {
                    TempData["ResultMessage"] = e.Message;
                    return(View("Error"));
                }
            }
        }
Exemple #12
0
        // GET: Entries/Create
        public ActionResult Create()
        {
            EntryCreateViewModel entryCreateViewModel = new EntryCreateViewModel();

            var boatList    = new List <BoatDropDownListViewModel>();
            var clubList    = new List <ClubDropDownListViewModel>();
            var regattaList = new List <RegattaDropDownListViewModel>();

            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BoatDTO, BoatDropDownListViewModel>();
                cfg.CreateMap <ClubDTO, ClubDropDownListViewModel>();
                cfg.CreateMap <RegattaDTO, RegattaDropDownListViewModel>();
            });

            using (var boatService = new BoatService())
                using (var clubService = new ClubService())
                    using (var regattaService = new RegattaService())
                    {
                        try
                        {
                            var allBoatsDto = boatService.EagerDisconnectedService.GetAll().Where(x => x.Active);
                            if (allBoatsDto == null)
                            {
                                throw new NullReferenceException();
                            }
                            var mapper = mapperConfig.CreateMapper();
                            mapper.Map(allBoatsDto, boatList);

                            var allclubsDto = clubService.EagerDisconnectedService.FindByInclude(x => x.Active);
                            if (allclubsDto == null)
                            {
                                throw new NullReferenceException();
                            }
                            var mapper2 = mapperConfig.CreateMapper();
                            mapper.Map(allclubsDto, clubList);

                            var allregattasDto = regattaService.EagerDisconnectedService.FindByInclude(x => x.Active);
                            if (allregattasDto == null)
                            {
                                throw new NullReferenceException();
                            }
                            var mapper3 = mapperConfig.CreateMapper();
                            mapper.Map(allregattasDto, regattaList);

                            ViewBag.BoatDropDownList    = new SelectList(boatList.OrderBy(b => b.FullBoatName), "Id", "FullBoatName");
                            ViewBag.ClubDropDownList    = new SelectList(clubList.OrderBy(c => c.Name), "Id", "Name");
                            ViewBag.RegattaDropDownList = new SelectList(regattaList.OrderBy(c => c.Name), "Id", "Name");

                            return(View());
                        }
                        catch (Exception e)
                        {
                            TempData["ResultMessage"] = e.Message;
                            return(View("Error"));
                        }
                    }
        }
 public BoatViewModel()
 {
     boatService   = new BoatService();
     addCommand    = new RelayCommand(Add);
     deleteCommand = new RelayCommand(Delete);
     updateCommand = new RelayCommand(Update);
     inputBoat     = new Boat();
     LoadBoatList();
 }
Exemple #14
0
 private List <Boat> GetAllBoats()
 {
     using (var context = new BoatContext())
     {
         var service = new BoatService(context);
         var boats   = service.GetAll();
         return(boats.ToList());
     }
 }
Exemple #15
0
        public ActionResult DeleteConfirmed(int id)
        {
            Boat boat = GetAllBoats().Find(b => b.Id == id);

            using (var context = new BoatContext())
            {
                var service = new BoatService(context);
                service.Remove(boat);
            }
            return(RedirectToAction("Index"));
        }
Exemple #16
0
        public IActionResult Rent(int page_num = 1)
        {
            ViewData["StyleSheet"] = "About";
            ViewData["Login"]      = CheckCookies();
            BoatService service = new BoatService();
            List <BoatCollectionViewModel> boats = service.GetAllBoat(new PageInfo {
                PageNumber = page_num, PageSize = 9
            }, "rent");

            return(View(boats));
        }
Exemple #17
0
        public IActionResult Index(int page_num = 1)
        {
            AuthorizationService a_service = new AuthorizationService();
            AccountViewModel     account   = a_service.GetAccountInfo(User.Identity.Name);

            if (account.AccountType.Equals("customer"))
            {
                MessageService r_service = new MessageService();
                account.Recalls = r_service.GetInbox(account.Id);
                BoatService b_service = new BoatService();
                account.Boats = b_service.GetUsersBoat(account.Id);
            }
            ViewData["StyleSheet"] = "Profile";
            ViewData["Login"]      = CheckCookies();
            return(View(account));
        }
Exemple #18
0
        public ActionResult Create(PocoClasses.Entries.Boat newBoat, string returnUrl)
        {
            Mapper.Initialize(cfg => cfg.CreateMap <PocoClasses.Entries.Boat, Boat>());
            Boat boat = Mapper.Map <Boat>(newBoat);

            if (ModelState.IsValid)
            {
                using (var context = new BoatContext())
                {
                    var service = new BoatService(context);
                    service.Add(boat);
                }
                return(Redirect(returnUrl));
            }
            return(View(newBoat));
        }
Exemple #19
0
        private static void Main(string[] args)
        {
            var context = new RoeiJeRotDbContext();

            IBoatService        boatService        = new BoatService(context);
            IReservationService reservationService = new ReservationService(context, boatService);

            var availableTypes =
                reservationService.AvailableBoatTypes(new DateTime(2019, 12, 26, 10, 00, 00),
                                                      TimeSpan.FromMinutes(120));

            foreach (var availableType in availableTypes)
            {
                Console.WriteLine(availableType.Name);
            }
        }
Exemple #20
0
        public async Task <IActionResult> Add(ICollection <IFormFile> files, BoatViewModel model)
        {
            if (ModelState.IsValid && files.Count > 0)
            {
                BoatService          b_service = new BoatService();
                AuthorizationService a_service = new AuthorizationService();
                model.Owner  = a_service.GetAccountInfo(User.Identity.Name).Id;
                model.Images = new List <byte[]>();
                foreach (IFormFile file in files)
                {
                    if (file.Length > 0)
                    {
                        BinaryReader reader = new BinaryReader(file.OpenReadStream());
                        model.Images.Add(reader.ReadBytes((int)file.Length));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Присутствует пустой файл");
                        return(RedirectToAction("Add", "Boat", model));
                    }
                }
                int code = b_service.AddBoat(model);
                switch (code)
                {
                case 0: return(RedirectToAction("Index", "User"));

                case 1:
                {
                    ModelState.AddModelError("", "Ошибка при добавлении записи");
                } break;
                }
            }
            else
            {
                ModelState.AddModelError("", "Неверное заполнение полей, либо остутствует изображение");
            }
            return(RedirectToAction("Add", "Boat", model));
        }
        /// <summary>
        /// Pobiera dane z bazy danych
        /// </summary>
        private void GetBoats()
        {
            var boatService = new BoatService();

            BoatsCollection = new ObservableCollection <BoatDto>(boatService.GetBoats());
        }
Exemple #22
0
 public BoatServiceTests()
 {
     _service = new BoatService(_mockRepo);
 }
Exemple #23
0
 // GET: api/<controller>
 /// <summary>
 /// Initalisation action
 /// </summary>
 /// <param name="boatService">
 /// Service class that contains the actions
 /// to implement required actions
 /// </param>
 public BoatController(BoatService boatService)
 {
     _boatService = boatService;
 }
Exemple #24
0
 public HomeController()
 {
     b_service = new BoatService();
     n_service = new NewsService();
 }