Esempio n. 1
0
        public ActionResult Create()
        {
            ViewBag.Teams = db.Teams.ToList();

            var PledgeVM = new CreatePledgeVM();
            PledgeVM.CurrencySymbol = CurrencyLogic.GetCurrencyPrefix(CurrentUser().Currency);
            PledgeVM.Pledge = new Pledge();
            PledgeVM.Pledge.Contributors.Add(new PledgeContributors { Sinner = CurrentUser(), SinnerID = CurrentUser().Id });

            return View(PledgeVM);
        }
Esempio n. 2
0
        public ActionResult Create(CreatePledgeVM pledgeVM)
        {
            ModelState.Clear();
            TryValidateModel(pledgeVM.Pledge);

            if (ModelState.IsValid)
            {

                var ThisUser = CurrentUser();
                if (!PledgesLogic.getCompletePledgeFromCreatePledgeVM(pledgeVM, db, ThisUser))
                {
                    Messaging.Add(Message.LevelEnum.alert_danger, "Sorry something went wrong trying to create your pledge.", Message.TypeEnum.TemporaryAlert, ThisUser);
                    db.SaveChanges();
                    return RedirectToAction("Create");
                }
                db.Pledges.Add(pledgeVM.Pledge );
                Messaging.Add(Message.LevelEnum.alert_success, "Thank you! your new pledge has been created.", Message.TypeEnum.StickyAlert, ThisUser);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return RedirectToAction("Create");
        }
Esempio n. 3
0
        public static bool getCompletePledgeFromCreatePledgeVM(CreatePledgeVM pledgeVM, ApplicationDbContext db, ApplicationUser user)
        {

            pledgeVM.Pledge.Contributors[0].IsOriginator = true;
            pledgeVM.Pledge.Contributors[0].Currency = user.Currency;

            if (pledgeVM.Pledge.Teams == null)
                pledgeVM.Pledge.Teams = new List<Team>();
            

            if (pledgeVM.TeamIDs != null)
            {
                foreach (var tId in pledgeVM.TeamIDs)
                {
                    int tIdInt = 0;
                    int.TryParse(tId, out tIdInt);
                    pledgeVM.Pledge.Teams.Add(db.Teams.FirstOrDefault(t => t.ID == tIdInt));
                }
            }

            if (pledgeVM.GalleryIDs != null)
            {
                foreach (var gIdStr in pledgeVM.GalleryIDs)
                {
                    var gID = GenericLogic.GetInt(gIdStr);
                    pledgeVM.Pledge.Gallery.Add(db.Images.FirstOrDefault(t => t.CalorieImageID == gID));
                }
            }

            if (pledgeVM.ActivityIDs != null)
            {
                if (pledgeVM.Pledge.Activity_Types == null)
                        pledgeVM.Pledge.Activity_Types = new List<PledgeActivity>();
                
                foreach (var ActivityID in pledgeVM.ActivityIDs)
                {
                    pledgeVM.Pledge.Activity_Types.Add(new PledgeActivity { Activity = (PledgeActivity.ActivityTypes)Enum.Parse(typeof(PledgeActivity.ActivityTypes), ActivityID) });
                }
            }

           if (!string.IsNullOrEmpty(pledgeVM.JustGivingCharityID))
            {
                var SelectedCharity = JustGivingLogic.getOrCreateCharityRecordFromJustGivingCharityID(pledgeVM.JustGivingCharityID);
                if (SelectedCharity == null)
                        return false;
                
                pledgeVM.Pledge.CharityID = SelectedCharity.ID;
            }

            return true;

        }