Пример #1
0
        public ActionResult Create(BeadCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            HttpPostedFileBase file = Request.Files["ImageData"];
            var service             = new BeadService();

            if (service.CreateBead(model))
            {
                TempData["SaveResult"] = "Your bead was added.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Bead could not be added.");

            return(View(model));
        }
        public bool CreateBead(BeadCreate model)
        {
            var entity = new Bead()
            {
                Brand       = model.Brand,
                Type        = model.Type,
                SubType     = model.SubType,
                Shape       = model.Shape,
                Size        = model.Size,
                Color       = model.Color,
                Quantity    = model.Quantity,
                Cost        = model.Cost,
                Description = model.Description,
                LocationId  = model.LocationId,
                SourceId    = model.SourceId,
                File        = _FileService.ConvertToBytes(model.File),
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Beads.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }