コード例 #1
0
        public IHttpActionResult Post(LarderCreate larder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateLarderService();

            service.CreateLarder(larder);
            return(Ok());
        }
コード例 #2
0
ファイル: myLarderService.cs プロジェクト: pfesenmeier/Larder
        public bool CreateLarder(LarderCreate model)
        {
            var entity = new LarderModel()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
            };

            using (var context = new CookbookContext())
            {
                context.Larders.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public ActionResult Create(LarderCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateLarderService();
            int?id      = service.CreateLarder(model);

            if (id != null)
            {
                TempData["SaveResult"] = "Your larder recipe was created.";
                return(RedirectToAction("Create", "Ingredient", new { isRecipe = false, id }));
            }
            else
            {
                ModelState.AddModelError("", "Larder recipe could not be created.");
                return(View(model));
            }
        }
コード例 #4
0
ファイル: LarderService.cs プロジェクト: pfesenmeier/Larder
        public int CreateLarder(LarderCreate model)
        {
            using (var context = new CookbookContext())
            {
                var season = new Season();
                if (model.Season == null)
                {
                    season.AuthorID = userId;
                    season.Summer   = false;
                    season.Fall     = false;
                    season.Winter   = false;
                    season.Spring   = false;
                }
                else
                {
                    season.AuthorID = userId;
                    season.Summer   = model.Season.Summer;
                    season.Fall     = model.Season.Fall;
                    season.Winter   = model.Season.Winter;
                    season.Spring   = model.Season.Spring;
                };

                context.Seasons.Add(season);
                context.SaveChanges();

                var entity = new LarderModel()
                {
                    AuthorID    = userId,
                    Name        = model.Name,
                    SeasonID    = season.ID,
                    Description = model.Description,
                    DateCreated = DateTimeOffset.UtcNow,
                };

                context.Larders.Add(entity);
                context.SaveChanges();
                return(entity.ID);
            }
        }