public ActionResult Create([Bind(Include = "Id,SendingMemberId,ReceivingMemberId,SendingBeerId,ReceiverBeerId,IsApproved,SendingComments,ReceivingComments")] Trade trade)
        {
            if (ModelState.IsValid)
            {
                db.Trades.Add(trade);
                db.SaveChanges();

                var recievingmember = db.Cellars.Find(trade.ReceivingMemberId).Member;
                var bodyTemplate    = "<p>Hi {0}</p><p>You have a trade offer made to you,please log into your account to see offer.</p>";
                var body            = string.Format(bodyTemplate, recievingmember.FirstName);
                MessagSender.SendEmail(recievingmember.Email, "CraftX Pending Trade Offer", body);

                var tradelisttypeviewmodel = new TradeListTypeViewModel {
                    TradeListType = TradeListType.PendingOffersMade
                };
                return(RedirectToAction("Index", new { model = tradelisttypeviewmodel }));
            }

            var userid        = User.Identity.GetUserId();
            var sendingmember = db.Members.Find(userid);
            var sendingcellar = sendingmember.Cellars.First();

            ViewBag.SendingBeerId = new SelectList(sendingcellar.Beers, "Id", "BeerName");
            return(View(trade));
        }
Beispiel #2
0
      public ActionResult Create([Bind(Include = "Id,Email,FirstName,LastName,City,State,Zip")] Member member)
      {
          if (ModelState.IsValid)
          {
              db.Members.Add(member);
              db.SaveChanges();
              return(RedirectToAction("Index"));
          }

          return(View(member));
      }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,MemberId,CellarName")] Cellar cellar)
        {
            if (ModelState.IsValid)
            {
                db.Cellars.Add(cellar);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MemberId = new SelectList(db.Members, "Id", "Email", cellar.MemberId);
            return(View(cellar));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    try {
                        var cellar = new Cellar {
                            CellarName = model.CellarName
                        };
                        var member = new Member
                        {
                            Id        = user.Id,
                            Email     = model.Email,
                            FirstName = model.FirstName,
                            LastName  = model.LastName,
                            City      = model.City,
                            State     = model.State,
                            Zip       = model.Zip,
                        };
                        member.Cellars.Add(cellar);

                        using (var db = new CapStoneProjectEntities5())
                        {
                            db.Members.Add(member);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception EX)
                    {
                        var x = 1;
                        //throw;
                    }


                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #5
0
        public ActionResult Create(int id, Beer beer)
        {
            if (ModelState.IsValid)
            {
                var existingbeer = db.Beers.Where(b => b.BeerName == beer.BeerName).FirstOrDefault();
                if (existingbeer == null)
                {
                    beer = db.Beers.Add(beer);
                }
                else
                {
                    beer = existingbeer;
                }
                var cellar = db.Cellars.Find(id);
                cellar.Beers.Add(beer);
                db.SaveChanges();
                return(RedirectToAction("Details", "Cellars", new { id = id }));
            }

            return(View(beer));
        }