Ejemplo n.º 1
0
        /// <summary>
        /// Make sure user exists in the database.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        ///
        public MFUser CreateUser(/*Facebook.FacebookUser*/ MFUser fbUser)
        {
            MFUser user = GetUserById(fbUser.UserId);

            if (user == null)
            {
                user = new MFUser()
                {
                    UserId     = fbUser.UserId,
                    Name       = fbUser.Name,
                    FirstName  = fbUser.FirstName,
                    LastName   = fbUser.LastName,
                    Email      = fbUser.Email,
                    Password   = fbUser.Password,
                    LastUpdate = DateTime.Now
                };
                context.MFUsers.Add(user);
            }
            else if (user.LastUpdate.AddDays(STALE_USER) < DateTime.Now)
            {
                user.Name       = (!string.IsNullOrEmpty(fbUser.Name) ? fbUser.Name : user.Name);
                user.FirstName  = (!string.IsNullOrEmpty(fbUser.FirstName) ? fbUser.FirstName : user.FirstName);
                user.LastName   = (!string.IsNullOrEmpty(fbUser.LastName) ? fbUser.LastName : user.LastName);
                user.Email      = (!string.IsNullOrEmpty(fbUser.Email) ? fbUser.Email : user.Email);
                user.Password   = (!string.IsNullOrEmpty(fbUser.Password) ? fbUser.Password : user.Password);
                user.LastUpdate = DateTime.Now;
            }

            return(user);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes an user from a specific event
        /// </summary>
        /// <param name="user"></param>
        /// <param name="eEvent"></param>
        ///
        public void RemoveUserFromEvent(MFUser user, Event eEvent)
        {
            Attending attending = context.Attendings.Where(r => (r.UserId == user.UserId) && (r.EventId == eEvent.EventId)).FirstOrDefault();

            if (attending != null)
            {
                context.Attendings.Remove(attending);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines if user is a member in the group
        /// </summary>
        /// <param name="user"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        ///
        public GroupRoleEnum IsUserInGroup(MFUser user, Group group)
        {
            GroupMember member = context.GroupMembers.Where(r => (r.UserId == user.UserId) && (r.GroupId == group.GroupId)).FirstOrDefault();

            if (member == null)
            {
                return(GroupRoleEnum.empty);
            }

            return((GroupRoleEnum)member.Role);
        }
Ejemplo n.º 4
0
 public static JsonUser FromDatabase(RaceDayAPI.Models.MFUser user)
 {
     return(new JsonUser
     {
         UserId = user.UserId,
         Name = user.Name,
         FirstName = user.FirstName,
         LastName = user.LastName,
         Email = user.Email,
         Password = user.Password,
         LastUpdate = user.LastUpdate
     });
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Assigns a default group and role to the user
 /// </summary>
 /// <param name="user"></param>
 /// <param name="group"></param>
 /// <param name="role"></param>
 ///
 public void DefaultGroup(MFUser user, Group group, GroupRoleEnum role)
 {
     if (IsUserInGroup(user, group) == GroupRoleEnum.empty)
     {
         GroupMember member = new GroupMember()
         {
             GroupId = group.GroupId,
             UserId  = user.UserId,
             Role    = (int)role
         };
         context.GroupMembers.Add(member);
     }
 }
Ejemplo n.º 6
0
        public RaceDayAPI.Models.MFUser ToDatabase()
        {
            RaceDayAPI.Models.MFUser user = new RaceDayAPI.Models.MFUser
            {
                UserId     = UserId,
                Email      = Email,
                Password   = Password,
                Name       = Name,
                FirstName  = FirstName,
                LastName   = LastName,
                LastUpdate = DateTime.Now
            };

            return(user);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds user as participating in the event
        /// </summary>
        /// <param name="user"></param>
        /// <param name="newEvent"></param>
        ///
        public void AddUserToEvent(MFUser user, Event newEvent, AttendingEnum isAttending)
        {
            Attending attending = context.Attendings.Where(r => (r.UserId == user.UserId) && (r.EventId == newEvent.EventId)).FirstOrDefault();

            if (attending == null)
            {
                attending = new Attending()
                {
                    UserId     = user.UserId,
                    EventId    = newEvent.EventId,
                    Attending1 = (int)isAttending
                };
                context.Attendings.Add(attending);
            }
            attending.Attending1 = (int)isAttending;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get events that the user has access to through assigned groups
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        ///
        public List <Event> GetUserEvents(MFUser user)
        {
            // Get an array of groups the user belongs to
            //
            int[] groups = new int[user.GroupMembers.Count];
            int   i      = 0;

            foreach (GroupMember member in user.GroupMembers)
            {
                groups[i] = member.GroupId;
                i++;
            }

            // Return events in the matching groups
            //
            DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

            return(context.Events.Where(r => groups.Contains(r.GroupId) && (r.Date >= start)).OrderBy(o => o.Date).ThenBy(o => o.Name).ToList());
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns the user group membership record
 /// </summary>
 /// <param name="user"></param>
 /// <param name="group"></param>
 /// <returns></returns>
 public GroupMember UserGroupMembership(MFUser user, Group group)
 {
     return(context.GroupMembers.Where(r => (r.UserId == user.UserId) && (r.GroupId == group.GroupId) && (r.Role >= (int)GroupRoleEnum.member)).FirstOrDefault());
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns all groups the user has access to
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 ///
 public List <GroupMember> UserMembership(MFUser user)
 {
     return(context.GroupMembers.Where(r => (r.UserId == user.UserId) && (r.Role >= (int)GroupRoleEnum.member)).ToList());
 }