コード例 #1
0
        internal void DeleteSweatyTShirt(long sweatyTShirtID)
        {
            SweatyTShirt sweatyTShirt = _context.SweatyTShirts.FirstOrDefault(o => o.SweatyTShirtID == sweatyTShirtID);

            if (sweatyTShirt == null)
            {
                throw new ArgumentException(string.Format("Unable to retrieve SweatyTShirt object: sweatyTShirtID =  {0}", sweatyTShirtID));
            }

            _context.SweatyTShirts.Remove(sweatyTShirt);
            _context.SaveChanges();
        }
コード例 #2
0
 public void AddSweatyTShirt(SweatyTShirt sweatyTShirt)
 {
     if (sweatyTShirt.CompetitionID <= 0)
     {
         throw new ApplicationException("Missing required property CompetitionID");
     }
     if (sweatyTShirt.UserID <= 0)
     {
         throw new ApplicationException("Missing required property UserID");
     }
     if (sweatyTShirt.Amount < SweatyTShirt.AmountMin || sweatyTShirt.Amount > SweatyTShirt.AmountMax)
     {
         throw new ApplicationException(string.Format("Amount must be between {0} and {1}.", SweatyTShirt.AmountMin, SweatyTShirt.AmountMax));
     }
     _context.SweatyTShirts.Add(sweatyTShirt);
     _context.SaveChanges();
 }
コード例 #3
0
        public ActionResult Index(SweatyTShirt sweatyTShirt)
        {
            int userID = UserID;

            sweatyTShirt.UserID = userID;

            using (CompetitionRepository competitionRepository = new CompetitionRepository())
            {
                if (sweatyTShirt.IsSave)
                {
                    sweatyTShirt.CreatedDate = DateTime.Now;
                    competitionRepository.AddSweatyTShirt(sweatyTShirt);
                    ViewBag.Purr = new Purr()
                    {
                        Title = "Success", Message = "Sweaty-T-Shirt was successfully added."
                    };
                }

                sweatyTShirt.Competitions = competitionRepository
                                            .GetUserInCompetitionsForUser(userID)
                                            .Where(o => o.IsActive)
                                            .Select(o => o.Competition).ToList();

                if (sweatyTShirt.Competitions.Count > 0)
                {
                    if (sweatyTShirt.CompetitionID > 0)
                    {
                        sweatyTShirt.Competition = sweatyTShirt.Competitions.FirstOrDefault(o => o.CompetitionID == sweatyTShirt.CompetitionID);
                    }
                    else
                    {
                        sweatyTShirt.Competition   = sweatyTShirt.Competitions[0];
                        sweatyTShirt.CompetitionID = sweatyTShirt.Competition.CompetitionID;
                    }

                    if (sweatyTShirt.Competition == null)
                    {
                        throw new ApplicationException(string.Format("Unable to retrieve Competition object for sweatyTShirt.CompetitionID {0}", sweatyTShirt.CompetitionID));
                    }

                    sweatyTShirt.Competition.CompetitionProgressBars =
                        ControllerHelpers.GetCompetitionProgressBars(competitionRepository,
                                                                     sweatyTShirt.CompetitionID);

                    if (sweatyTShirt.IsSave)
                    {
                        /* emails are sent in separate thread, see global.asax.cs*/
                        if (sweatyTShirt.PostToFacebook)
                        {
                            FacebookRepository.PostToFacebook(sweatyTShirt);
                        }
                    }
                }
            }

            if (TempData[ControllerHelpers.PURR] != null)
            {
                ViewBag.Purr = TempData[ControllerHelpers.PURR];
                TempData[ControllerHelpers.PURR] = null;
            }

            sweatyTShirt.IsSave      = false;
            sweatyTShirt.Description = null;
            //will get client side validation errors because manually adding model to view, need to clear them.
            ModelState.Clear();
            return(View(sweatyTShirt));
        }