Exemple #1
0
        public ActionResult Create(GoodCreateModel goodCreateModel, HttpPostedFileBase upload)
        {
            goodCreateModel.Date = DateTime.Now;

            if (ModelState.IsValid)
            {
                var good = _adminHelper.GoodCreateModelToGood(goodCreateModel, upload);

                _goodLogic.Add(good);
                return RedirectToAction("Index");
            }

            return View(goodCreateModel);
        }
Exemple #2
0
        public GoodCreateModel CreateGoodCreateModel()
        {
            GoodCreateModel goodCreateModel = new GoodCreateModel();

            var categories = _categoryLogic.GetAll().
                Select(s => new SelectListItem
                {
                    Text = s.Name,
                    Value = s.Id.ToString()
                }).ToList();

            var colors = _colorLogic.GetAll().
                Select(s => new SelectListItem
                {
                    Text = s.Name,
                    Value = s.Id.ToString()
                }).ToList();

            goodCreateModel.Categories = categories;
            goodCreateModel.Colors = colors;

            return goodCreateModel;
        }
Exemple #3
0
        public GoodDTO GoodCreateModelToGood(GoodCreateModel goodCreateModel, HttpPostedFileBase upload)
        {
            goodCreateModel.Date = DateTime.Now;

            Mapper.CreateMap<GoodCreateModel, GoodDTO>()
                  .ForMember("Category",
                      opt => opt.MapFrom(v => _categoryLogic.Get(v.CategoryId)))
                  .ForMember("Color",
                      opt => opt.MapFrom(v => _colorLogic.Get(v.ColorId)));

            var good = Mapper.Map<GoodCreateModel, GoodDTO>(goodCreateModel);

            if (upload != null && upload.ContentLength > 0)
            {
                good.ImageType = upload.ContentType;

                using (var reader = new BinaryReader(upload.InputStream))
                {
                    good.Image = reader.ReadBytes(upload.ContentLength);
                }
            }

            return good;
        }