コード例 #1
0
        /// <summary>
        /// This allows the user to enter a source for the recipe
        /// </summary>
        /// <param name="source"></param>
        /// <returns>200 Ok</returns>
        public IHttpActionResult Post(SourceCreate source)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateSourceService();

            if (!service.CreateSource(source))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
コード例 #2
0
        public bool CreateSource(SourceCreate model)
        {
            var entity =
                new Source()
            {
                OwnerId      = _userId,
                SourceName   = model.SourceName,
                SourceOrigin = model.SourceOrigin
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Sources.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public ActionResult Create(SourceCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = new SourceService();

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

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

            return(View(model));
        }
コード例 #4
0
        //___________________Create____________
        public bool CreateSource(SourceCreate model)
        {
            var entity = new Source()
            {
                Name           = model.Name,
                WebSite        = model.WebSite,
                ShowOrLocation = model.ShowOrLocation,
                Address        = model.Address,
                City           = model.City,
                State          = model.State,
                ZipCode        = model.ZipCode,
                Note           = model.Note
            };

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