Beispiel #1
0
        public void CreateTrailer(TrailerViewModel trailerViewModel)
        {
            var trailer = Mapper.Map <TrailerViewModel, Trailer_M>(trailerViewModel);

            _trailerRepository.Add(trailer);
            SaveTrailer();
        }
        public IActionResult PostTblTrailerTruckToDataBase([FromBody] TrailerViewModel nTrailer)
        {
            if (nTrailer != null)
            {
                if (!string.IsNullOrEmpty(nTrailer.ImagesString))
                {
                    var splitstring = nTrailer.ImagesString.Split(',');
                    nTrailer.Images = Convert.FromBase64String(splitstring[1]);
                }

                // Update to company
                int?CompanyId = null;
                if (nTrailer.CompanyID.HasValue)
                {
                    CompanyId = nTrailer.CompanyID.Value;
                }

                var hasData = this.repository.InsertTblTrailerTruckToDataBase(this.mapper.Map <TrailerViewModel, TblTrailerTruck>(nTrailer));
                if (hasData != null)
                {
                    if (CompanyId.HasValue)
                    {
                        this.repositoryTruckCompany.Add(new TblTruckHasCompany()
                        {
                            CompanyId  = CompanyId,
                            CreateDate = DateTime.Now,
                            Creator    = hasData.Creator,
                            TrailerId  = hasData.TrailerId
                        });
                    }
                    return(new JsonResult(hasData, this.DefaultJsonSettings));
                }
            }
            return(new StatusCodeResult(500));
        }
        public ActionResult Delete(Guid?id)
        {
            Trailer          trailer          = _trailerService.Find(id);
            TrailerViewModel trailerViewModel = Mapper.Map <TrailerViewModel>(trailer);

            return(PartialView("_DeleteTrailer", trailerViewModel));
        }
Beispiel #4
0
        public void UpdateTrailer(TrailerViewModel trailer)
        {
            var trailerToRemove = _trailerRepository.GetById(trailer.TrailerC);
            var updateTrailer   = Mapper.Map <TrailerViewModel, Trailer_M>(trailer);

            _trailerRepository.Delete(trailerToRemove);
            _trailerRepository.Add(updateTrailer);

            SaveTrailer();
        }
        public IActionResult PutTblTrailerTruckToDataBase(int key, [FromBody] TrailerViewModel uTrailer)
        {
            if (uTrailer != null && key > 0)
            {
                if (!string.IsNullOrEmpty(uTrailer.ImagesString))
                {
                    var splitstring = uTrailer.ImagesString.Split(',');
                    uTrailer.Images = Convert.FromBase64String(splitstring[1]);
                }

                // Update to company
                int?CompanyId = null;
                if (uTrailer.CompanyID.HasValue)
                {
                    CompanyId = uTrailer.CompanyID.Value;
                }

                var hasData = this.repository.UpdateTblTrailerTruckToDataBase(key, uTrailer);
                if (hasData != null)
                {
                    if (CompanyId.HasValue)
                    {
                        Expression <Func <TblTruckHasCompany, bool> > condition = c => c.TrailerId == hasData.TrailerId;
                        var hasCarHasCompany = this.repositoryTruckCompany.Find(condition);
                        if (hasCarHasCompany != null)
                        {
                            hasCarHasCompany.CompanyId  = CompanyId;
                            hasCarHasCompany.Modifyer   = hasData.Modifyer;
                            hasCarHasCompany.ModifyDate = hasData.ModifyDate;
                            // update to table car has company
                            this.repositoryTruckCompany.Update(hasCarHasCompany, hasCarHasCompany.TruckHasCompanyId);
                        }
                        else
                        {
                            this.repositoryTruckCompany.Add(new TblTruckHasCompany()
                            {
                                CompanyId  = CompanyId,
                                CreateDate = DateTime.Now,
                                Creator    = hasData.Creator,
                                TrailerId  = hasData.TrailerId,
                            });
                        }
                    }
                    return(new JsonResult(hasData, this.DefaultJsonSettings));
                }
                else
                {
                    return(new StatusCodeResult(500));
                }
            }
            else
            {
                return(NotFound(new { Error = String.Format($"Customer ID {key} has not been found") }));
            }
        }
        public ActionResult Edit(Guid id)
        {
            Trailer          trailer          = _trailerService.Find(id);
            TrailerViewModel trailerViewModel = Mapper.Map <TrailerViewModel>(trailer);

            var movies          = _moviesService.GetAll();
            var movieViewModels = Mapper.Map <IEnumerable <MoviesViewModel> >(movies);

            ViewBag.Movies = new SelectList(movieViewModels, "Id", "Name", trailer.MovieID);

            return(View("_EditTrailer", trailerViewModel));
        }
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trailer trailer = _trailerService.Find(id);

            if (trailer == null)
            {
                return(HttpNotFound());
            }
            TrailerViewModel trailerViewModel = Mapper.Map <TrailerViewModel>(trailer);

            return(View(trailerViewModel));
        }
        public ActionResult Edit(TrailerViewModel trailerViewModel, HttpPostedFileBase image)
        {
            if (image != null &&
                image.FileName != null &&
                CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
            {
                var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                image.SaveAs(path);
                trailerViewModel.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
            }

            Trailer trailer = Mapper.Map <Trailer>(trailerViewModel);

            _trailerService.Update(trailer, trailer.Id);
            return(RedirectToAction("Index"));
        }
Beispiel #9
0
        /// <summary>
        /// Register commands
        /// </summary>
        private void RegisterCommands()
        {
            LoadMovieCommand = new RelayCommand <MovieShort>(async movie => { await LoadMovieAsync(movie); });

            PlayMovieCommand = new RelayCommand(() =>
            {
                IsDownloadingMovie = true;
                DownloadMovie      = new DownloadMovieViewModel(Movie);
            });

            PlayTrailerCommand = new RelayCommand(async() =>
            {
                IsPlayingTrailer = true;
                IsTrailerLoading = true;
                Trailer          = await TrailerViewModel.CreateAsync(Movie, CancellationLoadingTrailerToken);
                IsTrailerLoading = false;
            });

            StopLoadingTrailerCommand = new RelayCommand(StopLoadingTrailer);
        }
        public ActionResult Create(TrailerViewModel trailerViewModel, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null &&
                    image.FileName != null &&
                    CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
                {
                    var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                    image.SaveAs(path);
                    trailerViewModel.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
                }


                trailerViewModel.Id = Guid.NewGuid();
                Trailer trailer = Mapper.Map <Trailer>(trailerViewModel);
                _trailerService.Create(trailer);
                return(RedirectToAction("Index"));
            }
            return(PartialView("_CreateTrailer", trailerViewModel));
        }
Beispiel #11
0
        public TrailerViewModel GetTrailerByCode(string trailerC)
        {
            TrailerViewModel result = new TrailerViewModel();

            var trailer = from a in _trailerRepository.GetAllQueryable()
                          join b in _driverRepository.GetAllQueryable() on new { a.DriverC }
            equals new { b.DriverC } into t1
            from b in t1.DefaultIfEmpty()
            join c in _modelRepository.GetAllQueryable() on new { a.ModelC, ObjectI = "1" } equals new { c.ModelC, c.ObjectI } into t2
            from c in t2.DefaultIfEmpty()
            where (a.TrailerC == trailerC)
            select new TrailerViewModel()
            {
                TrailerC    = a.TrailerC,
                TrailerNo   = a.TrailerNo,
                RegisteredD = a.RegisteredD,
                VIN         = a.VIN,
                DriverC     = a.DriverC,
                DriverN     = b != null ? b.LastN + " " + b.FirstN : "",
                RetiredD    = b != null ? b.RetiredD : null,
                IsActive    = a.IsActive,
                GrossWeight = a.GrossWeight,
                ModelC      = a.ModelC,
                ModelN      = c.ModelN,
                Situation   = a.Situation,
                FromDate    = a.FromDate,
                ToDate      = a.ToDate
            };

            if (trailer.Any())
            {
                var trailerList = trailer.ToList();
                result = trailerList[0];
                result.TrailerIndex = FindIndex(trailerC);
            }

            return(result);
        }
Beispiel #12
0
 public void Put(TrailerViewModel trailer)
 {
     _trailerService.UpdateTrailer(trailer);
     _maintenancePlanDetailService.UpdatePlan(trailer.MaintenanceItems, "1", trailer.TrailerC);
     _inspectionPlanDetailService.Add(trailer.Inspection, "1", trailer.TrailerC);
 }