Exemplo n.º 1
0
        public ActionResult Create(StringingMaterialCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            HttpPostedFileBase file = Request.Files["ImageData"];
            var service             = new StringingMaterialService();

            if (service.CreateStringingMaterial(model))
            {
                TempData["SaveResult"] = "Your stringing material was added.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Stringing material could not be added.");

            return(View(model));
        }
        public bool CreateStringingMaterial(StringingMaterialCreate model)
        {
            var entity = new StringingMaterial()
            {
                Type        = model.Type,
                Material    = model.Material,
                Size        = model.Size,
                Color       = model.Color,
                Length      = model.Length,
                Cost        = model.Cost,
                Description = model.Description,
                LocationId  = model.LocationId,
                SourceId    = model.SourceId,
                File        = _FileService.ConvertToBytes(model.File),
            };

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