コード例 #1
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();
            }
        }
コード例 #2
0
        public void JoinHangout(string userId, int hangoutId)
        {
            var Hangout = (from a in Hangout_db.Hangouts
                           where a.Id == hangoutId
                           select a).SingleOrDefault();
            var UserAccount = (from a in AspNetUsers_db.AspNetUsers
                               where a.Id == userId
                               select a).SingleOrDefault();
            if ((Hangout.AttendeeCount < Hangout.PartySize && Hangout.GenderRatio == false) ||
                (Hangout.AttendeeCount < Hangout.PartySize && Hangout.GenderRatio == true &&
                (UserAccount.Gender == 0 && Hangout.MaleAttendingCount < Hangout.PartySize / 2) || (UserAccount.Gender == 1 && Hangout.FemaleAttendingCount < Hangout.PartySize / 2)))
            {
                //if (AspNetUsers_Hangout_db.AspNetUsers_Hangouts.Any())
                //    {
                var UserHangout = (from a in AspNetUsers_Hangout_db.AspNetUsers_Hangouts
                                   where a.HangoutId == hangoutId && a.AspNetUsers == userId
                                   select a).SingleOrDefault();

                if (UserHangout == null)
                {
                    UserHangout = new AspNetUsers_Hangout
                    {
                        AspNetUsers = userId,
                        HangoutId = hangoutId,
                        IsRSVPd = true,
                        IsWaitlist = false,
                        Showed = true
                    };

                    AspNetUsers_Hangout_db.AspNetUsers_Hangouts.InsertOnSubmit(UserHangout);
                }
                else
                {
                    UserHangout.IsRSVPd = true;
                }
                //}

                try
                {
                    if (UserAccount.Gender == 0)
                    {
                        Hangout.MaleAttendingCount++;
                    }
                    else
                    {
                        Hangout.FemaleAttendingCount++;
                    }
                    Hangout.AttendeeCount++;

                    ActivityLog actLog = new ActivityLog
                    {
                        AspNetUserId = UserAccount.Id,
                        HangoutId = Hangout.Id,
                        TimeStamp = DateTime.UtcNow,
                        ActivityType = (int)ActivityType.Join
                    };

                    ActivityLog_db.ActivityLogs.InsertOnSubmit(actLog);

                    Hangout_db.SubmitChanges();
                    AspNetUsers_Hangout_db.SubmitChanges();
                    ActivityLog_db.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    // Make some adjustments.
                    // ...
                    // Try again.
                    Hangout_db.SubmitChanges();
                    AspNetUsers_Hangout_db.SubmitChanges();
                    ActivityLog_db.SubmitChanges();
                }
            }
            else
            {
                // Hangout too full/Hangout has too many boys/girls. Cant join.
            }
        }
コード例 #3
0
 partial void UpdateActivityLog(ActivityLog instance);
コード例 #4
0
 partial void DeleteActivityLog(ActivityLog instance);
コード例 #5
0
 partial void InsertActivityLog(ActivityLog instance);