예제 #1
0
        public static async Task <ResultsItem> DeleteBBThread(int threadId, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    BBThreads serviceThread = db.BBThreads.FirstOrDefault(x => x.ThreadId == threadId);
                    if (serviceThread == null)
                    {
                        return(ResultsItem.Error("This thread was not found or has already been deleted."));
                    }
                    if (serviceThread.UserId != user.UserId)
                    {
                        return(ResultsItem.Error("This thread belongs to another user."));
                    }

                    db.Remove(serviceThread);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully deleted this thread. Please refresh the page to see changes."));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to delete this thread. {ex.Message}"));
            }
        }
예제 #2
0
        public static async Task <ResultsItem> CreateBBThread(LocalCommunity.BBThread thread, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    thread.Message = thread.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });
                    thread.UserId  = user.UserId;

                    BBThreads serviceMessageThread = thread.Adapt <BBThreads>();
                    serviceMessageThread.CreateDate = DateTime.Now;
                    serviceMessageThread.UserId     = user.UserId;
                    serviceMessageThread.Message    = serviceMessageThread.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });
                    serviceMessageThread.Title      = serviceMessageThread.Title.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });

                    db.BBThreads.Add(serviceMessageThread);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully created a new thread"));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to create a new thread. {ex.Message}"));
            }
        }