public ActionResult Create(GlazeCreate model)
        {
            model.CreatedDate = DateTimeOffset.Now;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateGlazeService();

            //int createdGlaze = service.CreateGlaze(model);

            if (service.CreateGlaze(model))
            {
                TempData["SaveResult"] = "Your note was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Note could not be created.");

            return(View(model));
        }
Exemplo n.º 2
0
        //CREATE method
        public bool CreateGlaze(GlazeCreate model)
        {
            var entity =
                new Glaze()
            {
                OwnerId     = _userId,
                GlazeName   = model.GlazeName,
                Description = model.Description,
                MinCone     = model.MinCone,
                MaxCone     = model.MaxCone,
                Opacity     = model.Opacity,
                Surface     = model.Surface,
                MainColor   = model.MainColor,
                Atmosphere  = model.Atmosphere,
                FoodSafe    = model.FoodSafe,
                CreatedDate = DateTimeOffset.Now
            };

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