Example #1
0
        public JsonResult MarkShipped(ShippedVM vm)
        {
            string id = BifSessionData.IsInRole("ADMIN") ? vm.SenderId ?? BifSessionData.Id : BifSessionData.Id;

            var match = DAL.Context.Matches.Where(x => x.ExchangeId == BifSessionData.ExchangeId && x.SenderId == id)
                        .Select(x => new { Match = x, ExchangeName = x.Exchange.Name, SenderEmail = x.Sender.Email, SenderUsername = x.Sender.Profile.RedditUsername, RecipientEmail = x.Recipient.Email, RecipientUsername = x.Recipient.Profile.RedditUsername })
                        .FirstOrDefault();

            if (match == null)
            {
                return(Json(new { Success = false }));
            }

            match.Match.Carrier    = vm.Carrier;
            match.Match.TrackingNo = vm.TrackingNo;
            match.Match.ShipDate   = DateTime.Now;

            DAL.Context.SaveChanges();

            ShippingNoticeVM noticeVM = new ShippingNoticeVM {
                Carrier           = match.Match.Carrier,
                TrackingNo        = match.Match.TrackingNo,
                ExchangeName      = match.ExchangeName,
                SenderEmail       = match.SenderEmail,
                SenderUsername    = match.SenderUsername,
                RecipientEmail    = match.RecipientEmail,
                RecipientUsername = match.RecipientUsername
            };

            sendShippingEmails(noticeVM);

            return(Json(new { Success = true }));
        }
Example #2
0
        public JsonResult UpdateExclusion(string id, string userId)
        {
            userId = BifSessionData.IsInRole("ADMIN") ? userId ?? BifSessionData.Id : BifSessionData.Id;
            //int exclusions = Convert.ToInt32(BifSessionData.Claims.FirstOrDefault(x => x.Type == "http://21brews.com/identity/claims/allowed-exclusions")?.Value ?? "2");
            //if (userId != BifSessionData.Id)
            //    exclusions = Convert.ToInt32(DAL.Context.Claims.FirstOrDefault(x => x.Type == "http://21brews.com/identity/claims/allowed-exclusions")?.Value ?? "2");

            List <MatchPreference> preferences = DAL.Context.MatchPreferences.Where(x => x.UserId == userId && x.PreferenceType == MatchPreferenceType.NotUser).ToList();

            List <MatchPreference> existing = preferences.Where(x => x.Value == id).ToList();

            if (existing.Any())
            {
                DAL.Context.MatchPreferences.RemoveRange(existing);
                DAL.Context.SaveChanges();
                return(Json(new { Success = true, Action = "Unset", UserId = userId }));
            }

            int allowedExclusions = Convert.ToInt32(BifSessionData.Claims.FirstOrDefault(x => x.Type == "http://21brews.com/identity/claims/allowed-exclusions")?.Value ?? "2");

            if (preferences.Count >= allowedExclusions)
            {
                return(Json(new { Success = false, Action = "", UserId = userId }));
            }

            DAL.Context.MatchPreferences.Add(new MatchPreference {
                UserId         = userId,
                PreferenceType = MatchPreferenceType.NotUser,
                Value          = id
            });
            DAL.Context.SaveChanges();

            return(Json(new { Success = true, Action = "Set", UserId = userId }));
        }
Example #3
0
        public ActionResult MatchPreferences(string id, string userId)
        {
            int.TryParse(id, out int exchangeId);
            if (exchangeId == 0)
            {
                exchangeId = BifSessionData.ExchangeId;
            }

            userId = BifSessionData.IsInRole("ADMIN") ? userId ?? BifSessionData.Id : BifSessionData.Id;

            int exclusions = Convert.ToInt32(BifSessionData.Claims.FirstOrDefault(x => x.Type == "http://21brews.com/identity/claims/allowed-exclusions")?.Value ?? "2");

            if (userId != BifSessionData.Id)
            {
                exclusions = Convert.ToInt32(DAL.Context.Claims.FirstOrDefault(x => x.Type == "http://21brews.com/identity/claims/allowed-exclusions")?.Value ?? "2");
            }

            var allUsers = DAL.Context.Users.Where(x => x.UserStatus == IdentityUser.UserStatuses.Approved && x.Profile != null || x.Id == userId)
                           .Select(x => new {
                Id       = x.Id,
                Username = x.UserName ?? x.Profile.RedditUsername,
                City     = x.Profile.City,
                State    = x.Profile.State,
                Zip      = x.Profile.Zip,
                x.Profile.ZipCode
            }).OrderBy(x => x.Username).ToList();

            var me = allUsers.FirstOrDefault(x => x.Id == userId);

            List <KeyValuePair <MatchPreferenceType, string> > preferences = DAL.Context.MatchPreferences.Where(x => x.UserId == userId)
                                                                             .AsEnumerable().Select(x => new KeyValuePair <MatchPreferenceType, string>(x.PreferenceType, x.Value)).ToList();

            //Exchange exchange = DAL.Context.Exchanges.Find(exchangeId);

            MatchPreferencesVM vm = new MatchPreferencesVM {
                UserId = userId,
                //ExchangeName = exchange?.Name,
                AllUsers = allUsers.Select(x => new UserPublicProfile {
                    Id       = x.Id,
                    Username = x.Username,
                    Location = $"{x.City}, {x.State}",
                    Zip      = x.Zip,
                    Distance = DistanceTools.Haversine(x.ZipCode.Latitude, x.ZipCode.Longitude, me?.ZipCode.Latitude ?? 0m, me?.ZipCode.Longitude ?? 0m)
                }).ToList(),
                MatchPreferences  = preferences,
                AllowedExclusions = exclusions
            };

            return(View(vm));
        }
Example #4
0
        public JsonResult AddItem(BoxItem item, string userId, int exchangeId)
        {
            string id = BifSessionData.IsInRole("ADMIN") ? userId ?? BifSessionData.Id : BifSessionData.Id;

            Exchange exchange = DAL.Context.Exchanges.Find(BifSessionData.ExchangeId);

            if (exchange == null || exchange.CloseDate.AddDays(30) < DateTime.Today)
            {
                return(Json(new { Success = false, Message = "This Exchange is now closed. The box may no longer be edited" }));
            }

            if (item.UntappdId != null)
            {
                UntappdClient untappdClient = UntappdClient.Create();
                Beer          beer          = untappdClient.Lookup(item.UntappdId.Value);
                item.Name          = $"{beer.Name} ({beer.Brewery.Name})";
                item.UntappdRating = beer.Rating;
            }

            Item entity = new Item {
                UserId        = id,
                ExchangeId    = exchangeId,
                Format        = item.Format,
                Name          = item.Name,
                Type          = item.Type,
                UntappdId     = item.UntappdId,
                USOunces      = item.USOunces,
                Cost          = item.Cost,
                UntappdRating = item.UntappdRating
            };

            DAL.Context.Items.Add(entity);
            DAL.Context.SaveChanges();

            return(Json(new {
                Success = true,
                UserId = id,
                Id = entity.Id,
                ExchangeId = BifSessionData.ExchangeId,
                Format = item.Format,
                Name = item.Name,
                Type = item.Type,
                UntappdId = item.UntappdId,
                USOunces = item.USOunces,
                Cost = item.Cost,
                UntappdRating = item.UntappdRating == null ? null : Math.Round(item.UntappdRating ?? 0, 2).ToString("0.00")
            }));
        }
Example #5
0
        public PartialViewResult BoxSummary(string id, string userid)
        {
            int.TryParse(id, out int exchangeId);
            userid = BifSessionData.IsInRole("ADMIN") ? userid ?? BifSessionData.Id : BifSessionData.Id;

            Exchange exchange = DAL.Context.Exchanges.Find(exchangeId);

            List <Item> items = DAL.Context.Items.Where(x => x.UserId == userid && x.ExchangeId == exchangeId).ToList();

            BoxBuilder boxBuilder = new BoxBuilder(items)
                                    .SetMinimumOunces(exchange?.MinOunces)
                                    .SetMinimumBeerRating(exchange?.MinRating)
                                    .SetMinimumBoxRating(exchange?.MinBoxRating)
                                    .SetMinimumUnique(exchange?.MinUnique)
                                    .SetMinimumCost(exchange?.MinCost);

            return(PartialView("__BoxSummary", boxBuilder));
        }
Example #6
0
        public ActionResult Box(string id, string userId)
        {
            if (BifSessionData.UserStatus <= 0 || !BifSessionData.HasProfile)
            {
                ViewBag.Message = "Your user profile is still pending.  An administrator will review and approve your profile before you can use the Box Builder. Please check back soon.";
                return(View("Message"));
            }

            int.TryParse(id, out int exchangeId);
            if (exchangeId == 0)
            {
                exchangeId = BifSessionData.ExchangeId;
            }

            if (exchangeId == 0)
            {
                ViewBag.Message = "No Exchange selected.";
                return(View("Message"));
            }

            userId = BifSessionData.IsInRole("ADMIN") ? userId ?? BifSessionData.Id : BifSessionData.Id;

            Exchange exchange = DAL.Context.SignUps.Where(s => s.UserId == userId && s.ExchangeId == exchangeId).Select(x => x.Exchange).FirstOrDefault();

            if (exchange == null && exchangeId != 0)
            {
                return(RedirectToAction("", "Home"));
            }

            BoxVM vm = new BoxVM {
                UserId       = userId,
                ExchangeId   = exchangeId,
                ExchangeName = exchange?.Name ?? "Open",
                IsLocked     = exchange?.ShipDate < DateTime.Now.AddDays(-14),
                Items        = boxItems(userId, exchangeId),
            };

            return(View(vm));
        }
Example #7
0
        public ActionResult Index(ProfileVM vm)
        {
            string phoneNumber = vm.Phone;

            if (phoneNumber != null)
            {
                phoneNumber = Regex.Replace(vm.Phone, @"\D", "");
                if (phoneNumber.Length != 10)
                {
                    ModelState.AddModelError("Phone",
                                             "Phone Number is not valid.  Please enter your phone number with area code.  No extensions. (NNN-NNN-NNNN)");
                }
            }

            if (!ModelState.IsValid)
            {
                vm.Email = BifSessionData.Email;
                return(View(vm));
            }

            string id = BifSessionData.IsInRole("ADMIN") ? vm.Id ?? BifSessionData.Id : BifSessionData.Id;

            Profile profile = DAL.Context.Profiles.FirstOrDefault(x => x.Id == id) ?? new Profile {
                Id = id
            };

            profile.FullName        = vm.Name;
            profile.UntappdUsername = vm.UntappdUsername;
            profile.RedditUsername  = vm.RedditUsername;

            profile.Address       = vm.Address;
            profile.City          = vm.City;
            profile.State         = vm.State;
            profile.Zip           = vm.Zip;
            profile.PhoneNumber   = phoneNumber;
            profile.DeliveryNotes = vm.DeliveryNotes;

            profile.Piney  = vm.Piney;
            profile.Juicy  = vm.Juicy;
            profile.Tart   = vm.Tart;
            profile.Funky  = vm.Funky;
            profile.Malty  = vm.Malty;
            profile.Roasty = vm.Roasty;
            profile.Sweet  = vm.Sweet;
            profile.Smokey = vm.Smokey;
            profile.Spicy  = vm.Spicy;
            profile.Crisp  = vm.Crisp;

            profile.References = vm.References;
            profile.Comments   = vm.Comments;
            //profile.Wishlist = vm.Wishlist;
            profile.UpdateDate = DateTime.UtcNow;

            if (profile.CreateDate == null)
            {
                profile.CreateDate = DateTime.UtcNow;
                profile.Rating     = 4;
                DAL.Context.Profiles.Add(profile);
            }
            DAL.Context.SaveChanges();


            //bool success = signUp(, id, out string message);


            if (id == BifSessionData.Id)   // Only send if edited by self
            {
                createUserConfirmationEmail(id);
            }

            return(RedirectToAction("Index", "Home"));
        }
Example #8
0
        private bool signUp(int exchangeId, string userId, out string message)
        {
            var exchange = DAL.Context.Exchanges.Where(x => x.Id == exchangeId)
                           .Select(x => new { Exchange = x, SignUp = x.SignUps.Any(s => s.UserId == userId) }).FirstOrDefault();

            message = null;
            if (exchange?.Exchange == null)
            {
                message = "The requested Exchange cannot be found.";
                return(false);
            }

            if (exchange.Exchange.OpenDate <= DateTime.Now || exchange.Exchange.CloseDate >= DateTime.Now && !BifSessionData.IsInRole("ADMIN"))
            {
                message = "The requested Exchange is not currently open for signups.";
                return(false);
            }

            if (exchange.SignUp)
            {
                message = $"You are already registered for the {exchange.Exchange.Name} Exchange.";
                return(false);
            }

            if (!BifSessionData.HasProfile)
            {
                message = $"You have not yet completed your Profile.  Please update your <a href=\"{Url.Action("", "Profile")}\">Profile</a> before signing up.";
                return(false);
            }

            SignUp signup = new SignUp {
                ExchangeId = exchangeId,
                UserId     = userId,
                SignUpDate = DateTime.Now,
                Approved   = false
            };

            DAL.Context.SignUps.Add(signup);
            DAL.Context.SaveChanges();

            return(true);
        }
Example #9
0
        public ActionResult Index(string id = null)
        {
            if (BifSessionData.IsInRole("ADMIN"))
            {
                id = id ?? BifSessionData.Id;
            }
            else
            {
                id = BifSessionData.Id;
            }

            var user = DAL.Context.Users.Where(x => x.Id == id)
                       .Select(x => new { Email = x.Email, Profile = x.Profile, IsSignedUp = x.SignUps.Any(s => s.ExchangeId == BifSessionData.ExchangeId) })
                       .FirstOrDefault();

            if (user == null)
            {
                return(View("Error")); //TODO: Message View
            }
            if (user.Profile == null)
            {
                return(View(new ProfileVM {
                    Email = user.Email
                }));
            }

            string phoneNumber = user.Profile.PhoneNumber?.PadLeft(10, ' ') ?? "";

            ProfileVM vm = new ProfileVM {
                Id            = id,
                Name          = user.Profile.FullName,
                Address       = user.Profile.Address,
                City          = user.Profile.City,
                State         = user.Profile.State,
                Zip           = user.Profile.Zip,
                DeliveryNotes = user.Profile.DeliveryNotes,

                RedditUsername  = user.Profile.RedditUsername,
                UntappdUsername = user.Profile.UntappdUsername,

                References = user.Profile.References,
                //Wishlist = user.Profile.Wishlist,
                Comments = user.Profile.Comments,

                Piney  = user.Profile.Piney,
                Juicy  = user.Profile.Juicy,
                Tart   = user.Profile.Tart,
                Funky  = user.Profile.Funky,
                Malty  = user.Profile.Malty,
                Roasty = user.Profile.Roasty,
                Sweet  = user.Profile.Sweet,
                Smokey = user.Profile.Smokey,
                Spicy  = user.Profile.Spicy,
                Crisp  = user.Profile.Crisp,


                Phone = $"{phoneNumber}",
                Email = user.Email,

                UpdateDate = user.Profile.UpdateDate,
                //IsSignedUp = user.IsSignedUp
            };

            return(View(vm));
        }
Example #10
0
        //[HttpPost]
        //public JsonResult SignUpAsync(string userId, int exchangeId = 0) {
        //    bool success = signUp(exchangeId, userId, out string message);
        //    return Json(new {Success = success, Message = message});

        //}

        private bool doSignUp(Exchange exchange, string userId, string comment, out string message)
        {
            message = null;
            if (exchange == null)
            {
                message = "The requested Exchange cannot be found.";
                return(false);
            }

            DateTime signUpEndDate = exchange.MatchDate ?? exchange.OpenDate.AddDays(14);

            if ((DateTime.Now < exchange.OpenDate || DateTime.Now >= signUpEndDate) && !BifSessionData.IsInRole("ADMIN"))
            {
                message = "The requested Exchange is not currently open for signups.";
                return(false);
            }

            if (!BifSessionData.HasProfile)
            {
                message = $"You have not yet completed your Profile.  Please update your <a href=\"{Url.Action("", "Profile")}\">Profile</a> before signing up.";
                return(false);
            }

            SignUp signup = new SignUp {
                ExchangeId = exchange.Id,
                UserId     = userId,
                SignUpDate = DateTime.Now,
                Approved   = false,
                Comment    = comment
            };

            DAL.Context.SignUps.Add(signup);
            DAL.Context.SaveChanges();

            return(true);
        }
Example #11
0
        public ActionResult Index(string id)
        {
            id = BifSessionData.IsInRole("ADMIN") ? id ?? BifSessionData.Id : BifSessionData.Id;

            var match = DAL.Context.Exchanges.Where(x => x.Id == BifSessionData.ExchangeId)
                        .Select(x => new {
                Exchange = x,
                Match    = x.Matches.FirstOrDefault(m => m.SenderId == id),
            }).Select(x => new {
                Exchange      = x.Exchange,
                Match         = x.Match,
                Profile       = x.Match.Recipient.Profile,
                SignUpComment = x.Match.Recipient.Profile.SignUps.FirstOrDefault().Comment,
                Email         = x.Match.Recipient.Email
            }).FirstOrDefault();

            //var match = DAL.Context.Matches.Where(x => x.SenderId == id && x.ExchangeId == BifSessionData.ExchangeId)
            //    .Select(x => new {
            //        Profile = x.Recipient.Profile,
            //        Email = x.Recipient.Email,
            //        Match = x,
            //        Exchange = x.Exchange
            //    } ).FirstOrDefault();

            if (match?.Exchange.MatchDate != null && match.Exchange.MatchDate > DateTime.UtcNow.AddHours(-14))   // UTC -14 on a date is 9:00AM EST
            {
                ViewBag.MessageTitle = "No Matches Yet";
                ViewBag.Message      = $"Matches should be ready on {match.Exchange.MatchDate?.ToLongDateString()}. Don't worry, we'll let you know when they're posted. ";
                return(View("Message"));
            }

            if (match.Match == null)
            {
                ViewBag.MessageTitle = "No Matches Yet";
                ViewBag.Message      = $"Matches should be ready around {match.Exchange?.MatchDate?.ToLongDateString()}. Don't worry, we'll let you know when they're posted. ";
                return(View("Message"));
            }

            string phoneNumber = match.Profile.PhoneNumber?.PadLeft(10, ' ');

            DateTime hideDate = match.Exchange.ShipDate?.AddDays(14) ?? match.Exchange.MatchDate?.AddDays(28) ?? match.Exchange.CreateDate.AddDays(60);

            MatchVM vm = new MatchVM {
                Name    = match.Profile.FullName,
                Address = hideDate >= DateTime.Now ? match.Profile.Address : "",
                City    = hideDate >= DateTime.Now ? match.Profile.City : "",
                State   = hideDate >= DateTime.Now ? match.Profile.State : "",
                Zip     = hideDate >= DateTime.Now ? match.Profile.Zip : "",

                RedditUsername  = match.Profile.RedditUsername,
                UntappdUsername = match.Profile.UntappdUsername,

                References = match.Profile.References,
                //Wishlist = match.Profile.Wishlist,
                Comments = match.Profile.Comments,

                Piney  = match.Profile.Piney,
                Juicy  = match.Profile.Juicy,
                Tart   = match.Profile.Tart,
                Funky  = match.Profile.Funky,
                Malty  = match.Profile.Malty,
                Roasty = match.Profile.Roasty,
                Sweet  = match.Profile.Sweet,
                Smokey = match.Profile.Smokey,
                Spicy  = match.Profile.Spicy,
                Crisp  = match.Profile.Crisp,

                Phone = hideDate >= DateTime.Now ? phoneNumber == null ? null : $"{phoneNumber.Substring(0, 3)}-{phoneNumber.Substring(3, 3)}-{phoneNumber.Substring(6, 4)}" : "",
                Email = hideDate >= DateTime.Now ? match.Email : "",

                SenderId   = id,
                Carrier    = match.Match.Carrier,
                TrackingNo = match.Match.TrackingNo,

                ExchangeName = match.Exchange.Name,
                ShipDate     = match.Match.ShipDate,
                CloseDate    = match.Exchange.CloseDate
            };

            return(View("Index", vm));
        }