Esempio n. 1
0
        public void Update(TvDto tvDto)
        {
            Tv tv = Database.TvSets.Get(tvDto.Id);

            tv.Name             = tvDto.Name;
            tv.Company          = tvDto.Company;
            tv.Contrast         = tvDto.Contrast;
            tv.Description      = tvDto.Description;
            tv.ResponseTime     = tvDto.ResponseTime;
            tv.ScreenDiagonal   = tvDto.ScreenDiagonal;
            tv.ScreenResolution = tvDto.ScreenResolution;
            tv.SmartTv          = tvDto.SmartTv;
            tv.WiFi             = tvDto.WiFi;

            if (tvDto.Image != null)
            {
                tv.Image = tvDto.Image;
            }
            if (tvDto.Price != 0)
            {
                tv.Price = tvDto.Price;
            }

            Database.TvSets.Update(tv);
            Database.Save();
        }
Esempio n. 2
0
        private Tv MappingTvDtoToTv(TvDto tvDto)
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <TvDto, Tv>()).CreateMapper();
            var tv     = mapper.Map <TvDto, Tv>(tvDto);

            return(tv);
        }
Esempio n. 3
0
        public TvDto GetTv(int tvId)
        {
            Tv    tv    = Database.TvSets.Get(tvId);
            TvDto tvDto = MappingTvToTvDto(tv);

            return(tvDto);
        }
Esempio n. 4
0
        public ActionResult CreateTv(TvViewModel tvViewModel, HttpPostedFileBase uploadImage)
        {
            try
            {
                if (ModelState.IsValid && uploadImage != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }

                    TvDto tvDto = MappingTvViewModelToTvDto(tvViewModel);
                    tvDto.Image = imageData;
                    int tvId = tvService.Create(tvDto);

                    return(RedirectToAction("CreateTvSuccess", new { tvId }));
                }
                return(View(tvViewModel));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
Esempio n. 5
0
        private TvViewModel MappingTvDtoToTvViewModel(TvDto tvDto)
        {
            var mapper      = new MapperConfiguration(cfg => cfg.CreateMap <TvDto, TvViewModel>()).CreateMapper();
            var tvViewModel = mapper.Map <TvDto, TvViewModel>(tvDto);

            return(tvViewModel);
        }
Esempio n. 6
0
        public ActionResult EditTv(TvViewModel tvViewModel, HttpPostedFileBase uploadImage)
        {
            try
            {
                TvDto tvDto = MappingTvViewModelToTvDto(tvViewModel);

                if (uploadImage != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }
                    tvDto.Image = imageData;
                }
                else
                {
                    tvDto.Image = null;
                }


                tvService.Update(tvDto);

                TvDto tvDtoUpdated = tvService.GetTv(tvDto.Id);

                var tvViewModelUpdated = MappingTvDtoToTvViewModel(tvDtoUpdated);
                return(View("CreateTvSuccess", tvViewModelUpdated));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
Esempio n. 7
0
        public int Create(TvDto tvDto)
        {
            Tv tv = MappingTvDtoToTv(tvDto);

            Database.TvSets.Create(tv);
            Database.Save();
            return(tv.Id);
        }