Esempio n. 1
0
        private HangoutViewModel HangoutToHangoutViewModel(string userId, Hangout hangout)
        {
            var allAtendees = (from u in AspNetUsers_Hangout_db.AspNetUsers_Hangouts
                where u.HangoutId == hangout.Id && u.IsRSVPd == true
                select u);

            var hostAverageRating = (from u in OrganizerRatings_db.OrganizerRatings
                where u.OrganizerId == hangout.UserCreator
                select u);
            double sum = 0;

            foreach (var r in hostAverageRating)
            {
                sum += (double) r.Rating;
            }

            var hostAvg = sum/hostAverageRating.Count();
            bool isRsvp = false;
            var isRsvpUserHangout = (from u in AspNetUsers_Hangout_db.AspNetUsers_Hangouts
                where u.AspNetUsers == userId && u.HangoutId == hangout.Id && u.IsRSVPd == true
                select u).SingleOrDefault();
            if (isRsvpUserHangout != null)
            {
                isRsvp = isRsvpUserHangout.IsRSVPd;
            }

            var hangoutViewModel = new HangoutViewModel
            {
                Date = hangout.Date,
                Description = hangout.Description,
                Id = hangout.Id,
                Name = hangout.Name,
                Address = hangout.Address,
                ContactInfo = hangout.ContactInfo,
                OpenSpots = hangout.PartySize - allAtendees.Count(),
                HostName = GetUserName(hangout.UserCreator),
                MaleOpenSpots = (hangout.PartySize/2) - hangout.MaleAttendingCount,
                FemaleOpenSpots = (hangout.PartySize/2) - hangout.FemaleAttendingCount,
                GenderRatio = hangout.GenderRatio,
                HostAverageRating = Math.Round(hostAvg, 2),
                StartTime = hangout.StartTime,
                EndTime = hangout.EndTime,
                IsHost = hangout.UserCreator.Equals(userId) ? true : false,
                HostUser = GetUser(hangout.UserCreator),
                IsRsvp = isRsvp,
                Location = hangout.Location,
                ImageContent = hangout.ImageContent == null ? new byte[8] : hangout.ImageContent.ToArray(),
                ImageMimeType = hangout.ImageMimeType == null ? "none" : hangout.ImageMimeType
            };

            foreach (var a in allAtendees)
            {
                var user = (from y in AspNetUsers_db.AspNetUsers
                    where y.Id == a.AspNetUsers
                    select y).SingleOrDefault();
                hangoutViewModel.AttendingList.Add(GetUser(user.Id));
            }
            return hangoutViewModel;
        }
Esempio n. 2
0
        public void Create(CreateHangoutViewModel model)
        {
            Hangout hang = new Hangout
            {
                Date = model.Date,
                Description = model.Description,
                Name = model.Name,
                UserCreator = model.UserId,
                Location = model.Location,
                Address = model.Address,
                PartySize = model.PartySize,
                ContactInfo = model.ContactInfo,
                GenderRatio = model.GenderRatio,
                StartTime = model.StartTime,
                EndTime = model.EndTime,
                AttendeeCount = 1,
                IsCancelled = false,
                ImageContent = new byte[8],
                ImageMimeType = "0"
            };
            if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
            {
                using (var binaryReader = new BinaryReader(model.ImageUpload.InputStream))
                {
                    hang.ImageContent = binaryReader.ReadBytes(model.ImageUpload.ContentLength);
                }
                hang.ImageMimeType = model.ImageUpload.ContentType;
            }

            string gend = GetUserGender(model.UserId);
            if(gend.Equals("male"))
            {
                hang.MaleAttendingCount++;
            }
            else if(gend.Equals("female"))
            {
                hang.FemaleAttendingCount++;
            }

            //Need to grab user in controller
            Hangout_db.Hangouts.InsertOnSubmit(hang);

            try
            {
                Hangout_db.SubmitChanges();
                // TODO: Add log entry for create event.
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // Make some adjustments.
                // ...
                // Try again.
                Hangout_db.SubmitChanges();
            }

            ActivityLog actLog = new ActivityLog
            {
                AspNetUserId = model.UserId,
                HangoutId = hang.Id,
                TimeStamp = DateTime.UtcNow,
                ActivityType = (int) ActivityType.Create
            };

            ActivityLog_db.ActivityLogs.InsertOnSubmit(actLog);

            try
            {
                ActivityLog_db.SubmitChanges();
                // TODO: Add log entry for create event.
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // Make some adjustments.
                // ...
                // Try again.
                ActivityLog_db.SubmitChanges();
            }
        }
Esempio n. 3
0
 partial void UpdateHangout(Hangout instance);
Esempio n. 4
0
 partial void DeleteHangout(Hangout instance);
Esempio n. 5
0
 partial void InsertHangout(Hangout instance);