Exemplo n.º 1
0
        Int64 IActivityLogDataAccess.Add(ActivityLogEntity activityLogEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Add(activityLogEntity, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = AddTran(activityLogEntity, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        Int64 IActivityLogDataAccess.Delete(ActivityLogEntity activityLogEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Delete(activityLogEntity, filterExpression, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = DeleteTran(activityLogEntity, filterExpression, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void InvokeOnNewLog(ActivityLogEntity log)
        {
            LogHandler handler = OnNewLog;

            if (handler != null)
            {
                handler(log);
            }
        }
        public async Task RetweetHandler(int id)
        {
            ClaimsPrincipal user   = _iHttpContextAccessor.HttpContext.User;
            int             userID = int.Parse(ClaimExtensions.GetUserId(user));

            var tweet = await _dbContext.Tweets.Where(p => p.Id == id).Select(p =>
                                                                              new TweetEntity()
            {
                Id           = p.Id,
                Content      = p.Content,
                CreatedAt    = p.CreatedAt,
                CreatorId    = p.CreatorId,
                LikeCount    = p.LikeCount,
                RetweetCount = p.RetweetCount,
                IsRetweet    = p.IsRetweet,
            }).SingleOrDefaultAsync();

            if (tweet is null)
            {
                throw new TwitterApiException(400, "Invalid tweet id");
            }
            tweet.RetweetCount++;

            _dbContext.Tweets.Update(tweet);
            await _dbContext.SaveChangesAsync();

            var relation = new UserTweetRelationEntity();

            relation.TweetId = tweet.Id;
            relation.UserId  = userID;
            await _dbContext.UserTweetRelations.AddRangeAsync(relation);

            await _dbContext.SaveChangesAsync();

            var relationn = new TweetRetweeterRelationEntity();

            relationn.TweetId     = tweet.Id;
            relationn.RetweeterId = userID;
            await _dbContext.TweetRetweeterRelations.AddRangeAsync(relationn);

            await _dbContext.SaveChangesAsync();

            var activityLog = new ActivityLogEntity()
            {
                ActorId        = userID,
                ActorName      = user.Identity.Name,
                ActionTypeId   = (int)ActionLogEnums.Retweet,
                ActionTypeName = "Retweet",
                TargetTweetId  = tweet.Id,
                TargetUserId   = tweet.CreatorId,
                Date           = DateTime.Now,
            };

            await _dbContext.ActivityLogs.AddAsync(activityLog);

            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 5
0
        private Int64 UpdateTran(ActivityLogEntity activityLogEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ActivityLog_SET";

            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand cmd = db.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option, db);
                AddOutputParameter(cmd, db);
                AddFilterExpressionParameter(cmd, filterExpression, db);

                db.AddInParameter(cmd, "@ActivityLogID", DbType.Int64, activityLogEntity.ActivityLogID);
                db.AddInParameter(cmd, "@UserId", DbType.Guid, activityLogEntity.UserId);
                db.AddInParameter(cmd, "@Activity", DbType.String, activityLogEntity.Activity);
                db.AddInParameter(cmd, "@PageUrl", DbType.String, activityLogEntity.PageUrl);
                db.AddInParameter(cmd, "@ActivityDate", DbType.DateTime, activityLogEntity.ActivityDate);

                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                try
                {
                    using (IDataReader reader = db.ExecuteReader(cmd, transaction))
                    {
                        returnCode = GetReturnCodeFromParameter(cmd);
                    }

                    if (returnCode > 0)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ArgumentException("Error Code." + returnCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    transaction.Dispose();
                    connection.Close();
                    connection = null;
                }
            }

            return(returnCode);
        }
Exemplo n.º 6
0
        protected void lvActivityLog_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 ActivityLogID;

            Int64.TryParse(e.CommandArgument.ToString(), out ActivityLogID);

            if (ActivityLogID > 0)
            {
                if (string.Equals(e.CommandName, "EditItem"))
                {
                    _ActivityLogID = ActivityLogID;
                }
                else if (string.Equals(e.CommandName, "DeleteItem"))
                {
                    try
                    {
                        Int64 result = -1;

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(ActivityLogEntity.FLD_NAME_ActivityLogID, ActivityLogID.ToString(), SQLMatchType.Equal);

                        ActivityLogEntity activityLogEntity = new ActivityLogEntity();


                        result = FCCActivityLog.GetFacadeCreate().Delete(activityLogEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _ActivityLogID     = 0;
                            _ActivityLogEntity = new ActivityLogEntity();
                            PrepareInitialView();
                            BindActivityLogList();

                            MiscUtil.ShowMessage(lblMessage, "Activity Log has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete Activity Log.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
Exemplo n.º 7
0
        private Int64 Update(ActivityLogEntity activityLogEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ActivityLog_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);

                Database.AddInParameter(cmd, "@ActivityLogID", DbType.Int64, activityLogEntity.ActivityLogID);
                Database.AddInParameter(cmd, "@UserId", DbType.Guid, activityLogEntity.UserId);
                Database.AddInParameter(cmd, "@Activity", DbType.String, activityLogEntity.Activity);
                Database.AddInParameter(cmd, "@PageUrl", DbType.String, activityLogEntity.PageUrl);
                Database.AddInParameter(cmd, "@ActivityDate", DbType.DateTime, activityLogEntity.ActivityDate);

                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("ActivityLogEntity already exists. Please specify another ActivityLogEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("ActivityLogEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("ActivityLogEntity already exists. Please specify another ActivityLogEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
Exemplo n.º 8
0
        public async Task FollowUserHandler(FollowUserDto request)
        {
            ClaimsPrincipal user         = _iHttpContextAccessor.HttpContext.User;
            string          followerName = user.Identity.Name.ToLower();
            string          followerID   = ClaimExtensions.GetUserId(user);
            var             following    = await _dbContext.Users.Where(p => p.Username == request.Username.ToLower()).Select(p =>
                                                                                                                              new UserEntity()
            {
                Id                  = p.Id,
                Username            = p.Username,
                Password            = p.Password,
                Email               = p.Email,
                UserFollowRelations = p.UserFollowRelations,
            }).SingleOrDefaultAsync();

            var relation = new UserFollowRelationEntity();

            relation.FollowerId  = int.Parse(followerID);
            relation.FollowingId = following.Id;
            await _dbContext.UserFollowRelations.AddAsync(relation);

            await _dbContext.SaveChangesAsync();

            var activityLog = new ActivityLogEntity()
            {
                ActorId        = int.Parse(followerID),
                ActorName      = user.Identity.Name,
                ActionTypeId   = (int)ActionLogEnums.Follow,
                ActionTypeName = "Follow",
                TargetTweetId  = -1,
                TargetUserId   = following.Id,
                Date           = DateTime.Now,
            };

            await _dbContext.ActivityLogs.AddAsync(activityLog);

            await _dbContext.SaveChangesAsync();
        }
        public ActivityLogEntity AddLog(string descriminator,
                                        ActivityLogLevel level     = ActivityLogLevel.Info,
                                        string message             = null,
                                        IClassifiable classifiable = null,
                                        object contract            = null)
        {
            var entry = new ActivityLogEntity();

            entry.Descriminator = descriminator;
            entry.Message       = message;
            entry.Level         = level;
            if (contract != null)
            {
                entry.SetValue(contract);
            }
            if (classifiable != null)
            {
                entry.ClassifiableId   = classifiable.Id;
                entry.ClassifiableName = classifiable.ObjectName;
            }
            entry = logRepo.Save(entry);
            InvokeOnNewLog(entry);
            return(entry);
        }
Exemplo n.º 10
0
 Int64 IActivityLogFacade.Delete(ActivityLogEntity activityLogEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateActivityLogDataAccess().Delete(activityLogEntity, filterExpression, option, reqTran));
 }
Exemplo n.º 11
0
 Int64 IActivityLogFacade.Add(ActivityLogEntity activityLogEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateActivityLogDataAccess().Add(activityLogEntity, option, reqTran));
 }