コード例 #1
0
        public bool CreateGoal(GoalCreate model)
        {
            var newGoal = new Goal()
            {
                OwnerId = _userId, GoalText = model.GoalText
            };
            ApplicationUser applicationUser = _db.Users.FirstOrDefault(x => x.Id == model.CurrentUserId);

            applicationUser.GoalRunningTotal += 1;
            _db.Goals.Add(newGoal);
            return(_db.SaveChanges() == 1);
        }
コード例 #2
0
        public ActionResult Create(GoalCreate model)
        {
            var userId = User.Identity.GetUserId();

            model.CurrentUserId = userId;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                GoalService service = CreateGoalService();
                service.CreateGoal(model);
                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
        public IHttpActionResult Post(int dayID, GoalCreate goal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGoalService();

            if (!service.CreateGoal(dayID, goal))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
コード例 #4
0
        public bool CreateGoal(GoalCreate model)
        {
            var entity =
                new Goal()
            {
                OwnerID    = _userID,
                GoalName   = model.GoalName,
                GoalColor  = model.GoalColor,
                GoalRarity = model.GoalRarity,
            };

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

            var service = CreateGoalService();

            if (service.CreateGoal(model))
            {
                TempData["SaveResult"] = "Goal created successfully.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Failed to create goal.");
            return(View(model));
        }
コード例 #6
0
        //CREATE NEW GOAL
        public bool CreateGoal(GoalCreate model)
        {
            var entity =
                new Goal()
            {
                Title          = model.Title,
                Description    = model.Description,
                DateCreatedUtc = DateTimeOffset.Now,
                Completed      = false,
                OwnerId        = _userId
            };

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

            var service = CreateGoalService();

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

            ModelState.AddModelError("", "We're sorry, your goal could not be created. Please try again.");
            return(View(model));
        }
コード例 #8
0
        // Post - Create
        public bool CreateGoal(GoalCreate model)
        {
            var entity =
                new Goal
            {
                GoalTitle   = model.GoalTitle,
                GoalContent = model.GoalContent,
                GoalType    = (Data.GoalType)model.GoalType,
                Difficulty  = model.Difficulty,
                StartDate   = model.StartDate,
                EndDate     = model.EndDate,
                Completed   = model.Completed,
                ProfileId   = model.ProfileId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Goals.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #9
0
ファイル: GoalService.cs プロジェクト: bssokolski/PurpleRain2
        public bool CreateGoal(int dayid, GoalCreate model)
        {
            var entity =
                new Data.Goal()
            {
                GoalName = model.GoalName,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Goals.Add(entity);
                if (ctx.SaveChanges() == 1)
                {
                    var days =
                        ctx
                        .Days
                        .Single(e => e.DayID == dayid && e.OwnerID == _userId);

                    days.GoalID = entity.GoalID;
                    return(ctx.SaveChanges() == 1);
                }
                return(false);
            }
        }