예제 #1
0
        public IActionResult Product(int boat_id)
        {
            BoatService   service = new BoatService();
            BoatViewModel boat    = service.GetBoatInfo(boat_id);

            return(View(boat));
        }
        public IActionResult Index()
        {
            var model = new BoatViewModel
            {
                ImageUrls = _webHostEnvironment.WebRootFileProvider.GetDirectoryContents("Content/Boat/Interior/")
                            .Select(x => $"../Content/Boat/Interior/{x.Name}").ToList(),
                Title          = _localizer["Boat.Title"],
                Subtitle       = _localizer["Boat.Subtitle"],
                InteriorTitle  = _localizer["Boat.Interior.Title"],
                InteriorText   = _localizer["Boat.Interior.Text"],
                LayoutTitle    = _localizer["Boat.Layout.Title"],
                LayoutText     = _localizer["Boat.Layout.Text"],
                EquipmentTitle = _localizer["Boat.Equipment.Title"],
                IconAutopilot  = _localizer["Boat.Icon.Autopilot"],
                IconEngine     = _localizer["Boat.Icon.Engine"],
                IconFire       = _localizer["Boat.Icon.Fire"],
                IconFishing    = _localizer["Boat.Icon.Fishing"],
                IconInflatable = _localizer["Boat.Icon.Inflatable"],
                IconLifeRaft   = _localizer["Boat.Icon.LifeRaft"],
                IconMap        = _localizer["Boat.Icon.Map"],
                IconRadar      = _localizer["Boat.Icon.Radar"],
                IconSignal     = _localizer["Boat.Icon.Signal"],
                IconSolar      = _localizer["Boat.Icon.Solar"],
                IconGrill      = _localizer["Boat.Icon.Grill"],
                IconFridge     = _localizer["Boat.Icon.Fridge"],
                IconFreezer    = _localizer["Boat.Icon.Freezer"],
                OverlapText    = _localizer["Boat.Overlap.Text"],
                OverlapTitle   = _localizer["Boat.Overlap.Title"]
            };

            return(View(model));
        }
예제 #3
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));
        }
예제 #4
0
        public IActionResult Edit(int id)
        {
            BoatService   service = new BoatService();
            BoatViewModel model   = service.GetBoatInfo(id);

            return(View(model));
        }
예제 #5
0
        public int InsertBoat(BoatViewModel boat)
        {
            var dbBoat = new Boat()
            {
                BoatNumber = boat.BoatNumber,
                BoatType   = boat.BoatType,
                Booked     = boat.Booked
            };

            return(boatRepository.Insert(dbBoat));
        }
예제 #6
0
        public void UpdateBoat(BoatViewModel boat)
        {
            var dbBoat = new Boat()
            {
                Id         = boat.Id,
                BoatNumber = boat.BoatNumber,
                BoatType   = boat.BoatType,
                Booked     = boat.Booked
            };

            boatRepository.Update(dbBoat);
        }
예제 #7
0
        public BoatViewModel FindBoatByNumber(int boatNumber)
        {
            var dbBoat = boatRepository.All.Where(x => x.BoatNumber == boatNumber).FirstOrDefault();
            var boat   = new BoatViewModel()
            {
                Id             = dbBoat.Id,
                BoatNumber     = dbBoat.BoatNumber,
                BoatType       = dbBoat.BoatType,
                Booked         = dbBoat.Booked,
                BoatTypeString = BoatTypeString(dbBoat.BoatType),
            };

            return(boat);
        }
예제 #8
0
        /// <summary>
        /// Получение полной информации по лодке
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BoatViewModel GetBoatInfo(int id)
        {
            Boat          b_result  = b_repository.Boat_GetById(id);
            BoatModel     bm_result = bm_repository.GetById(b_result.ModelId);
            List <byte[]> images    = null;
            List <Image>  i_result  = i_repository.GetAllByOwnerId(b_result.Id).ToList();

            if (i_result != null)
            {
                images = new List <byte[]>();
                foreach (Image image in i_result)
                {
                    images.Add(image.Content);
                }
            }
            List <RentViewModel> rents    = null;
            List <Rent>          r_result = r_repository.GetByOwnerId(b_result.Id).ToList();

            if (r_result != null)
            {
                rents = new List <RentViewModel>();
                foreach (Rent rent in r_result)
                {
                    rents.Add(new RentViewModel {
                        StatusFrom = rent.From, StatusTo = rent.To
                    });
                }
            }
            BoatViewModel boat = new BoatViewModel
            {
                ID               = b_result.Id,
                Type             = b_result.BoatType,
                Speed            = b_result.Speed,
                Cost             = b_result.Cost,
                Description      = b_result.Description,
                Kind             = b_result.Kind,
                Status           = b_result.Status,
                Owner            = b_result.OwnerId,
                BoatModel        = bm_result.Name,
                Lenght           = bm_result.Length,
                Width            = bm_result.Width,
                Displacement     = bm_result.Displacement,
                ManufacturerName = bm_result.ManufacturerName,
                Images           = images,
                Rents            = rents
            };

            return(boat);
        }
예제 #9
0
 /// <summary>
 /// Добавление новой лодки
 /// </summary>
 /// <param name="data"></param>
 /// <param name="images"></param>
 /// <returns></returns>
 public int AddBoat(BoatViewModel data)
 {
     try
     {
         if (bm_repository.GetByName(data.BoatModel) == null)
         {
             BoatModel model = new BoatModel
             {
                 Name             = data.BoatModel,
                 Length           = data.Lenght,
                 Width            = data.Width,
                 Displacement     = data.Displacement,
                 ManufacturerName = data.ManufacturerName
             };
             bm_repository.Create(model);
         }
         int  model_id = bm_repository.GetByName(data.BoatModel).Id;
         Boat boat     = new Boat
         {
             BoatType    = data.Type,
             Speed       = data.Speed,
             Cost        = data.Cost,
             Description = data.Description,
             Kind        = data.Kind,
             Status      = true,
             OwnerId     = data.Owner,
             ModelId     = model_id
         };
         int boat_id = b_repository.Boat_Create(boat);
         if (data.Images != null && data.Images.Count > 0)
         {
             foreach (byte[] content in data.Images)
             {
                 Image image = new Image
                 {
                     Content = content,
                     OwnerId = boat_id
                 };
                 i_repository.Create(image);
             }
         }
         return(0);
     }
     catch
     {
         return(1);
     }
 }
예제 #10
0
        public List <BoatViewModel> allBoats()
        {
            var dbBoats = boatRepository.All.ToList();
            var boats   = new List <BoatViewModel>();

            foreach (var dbBoat in dbBoats)
            {
                var boat = new BoatViewModel()
                {
                    Id             = dbBoat.Id,
                    BoatNumber     = dbBoat.BoatNumber,
                    BoatType       = dbBoat.BoatType,
                    BoatTypeString = BoatTypeString(dbBoat.BoatType),
                    Booked         = dbBoat.Booked
                };
                boats.Add(boat);
            }
            return(boats);
        }
예제 #11
0
 /// <summary>
 /// Редактирование лодки
 /// </summary>
 /// <param name="data"></param>
 /// <param name="images"></param>
 /// <returns></returns>
 public int EditBoat(BoatViewModel data)
 {
     try
     {
         Boat boat = new Boat
         {
             Id          = data.ID,
             BoatType    = data.Type,
             Speed       = data.Speed,
             Cost        = data.Cost,
             Description = data.Description,
             Kind        = data.Kind,
             Status      = true,
         };
         b_repository.Boat_Update(boat);
         return(0);
     }
     catch
     {
         return(1);
     }
 }
예제 #12
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));
        }
예제 #13
0
 public ActionResult Edit(BoatViewModel boat)
 {
     rentalHelper.UpdateBoat(boat);
     return(RedirectToAction("", ""));
 }
예제 #14
0
        public ActionResult Create(BoatViewModel boat)
        {
            int id = rentalHelper.InsertBoat(boat);

            return(RedirectToAction("", ""));
        }
예제 #15
0
        public IActionResult Product(int boat_id)
        {
            BoatViewModel boat = b_service.GetBoatInfo(boat_id);

            return(View(boat));
        }