Ejemplo n.º 1
0
        /// <summary>
        /// Add notification about action to db.
        /// </summary>
        /// <param name="userOneId">user one id.</param>
        /// <param name="userTwoId">user two id.</param>
        /// <param name="action">action.</param>
        /// <param name="actionTime">time of action.</param>
        /// <returns>true if operations success; otherwise, false.</returns>
        public static bool AddNotification(int userOneId, int userTwoId, UserActions action, DateTime actionTime)
        {
            using (var DBcontext = new LinqToSqlDataContext())
            {
                // new notification
                Notification newNotification;
                switch (action)
                {
                    case UserActions.AcceptFriendship:
                        newNotification = new Notification
                        {
                            user_one = userOneId,
                            user_two = userTwoId,
                            time = actionTime,
                            accept_friendship = true
                        };
                        break;

                    case UserActions.RejectFriendship:
                        newNotification = new Notification
                        {
                            user_one = userOneId,
                            user_two = userTwoId,
                            time = actionTime,
                            reject_friendship = true
                        };
                        break;

                    case UserActions.SendFriendshipRequest:
                        newNotification = new Notification
                        {
                            user_one = userOneId,
                            user_two = userTwoId,
                            time = actionTime,
                            send_friendship = true
                        };
                        break;

                    case UserActions.CancelFriendshipRequest:
                        newNotification = new Notification
                        {
                            user_one = userOneId,
                            user_two = userTwoId,
                            time = actionTime,
                            cancel_friendship = true
                        };
                        break;

                    case UserActions.RemoveFromFriends:
                        newNotification = new Notification
                        {
                            user_one = userOneId,
                            user_two = userTwoId,
                            time = actionTime,
                            remove_friend = true
                        };
                        break;

                    default:
                        return false;
                }

                DBcontext.Notifications.InsertOnSubmit(newNotification);
                try
                {
                    DBcontext.SubmitChanges();
                    return true;
                }
                catch (Exception e)
                {
                    log.Error(e);
                    return false;
                }
            }
        }
Ejemplo n.º 2
0
 partial void DeleteNotification(Notification instance);
Ejemplo n.º 3
0
 partial void UpdateNotification(Notification instance);
Ejemplo n.º 4
0
 partial void InsertNotification(Notification instance);
Ejemplo n.º 5
0
		private void detach_Notifications1(Notification entity)
		{
			this.SendPropertyChanging();
			entity.User1 = null;
		}
Ejemplo n.º 6
0
		private void attach_Notifications(Notification entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}