Ejemplo n.º 1
0
        public Organization AddNewOrganization(CreateOrganization organizationBasic, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newOrg = CreatEmptyOrganization();

            newOrg.OrganizationId    = CurrenUser;
            newOrg.OrganizationName  = organizationBasic.OrganizationName;
            newOrg.EOrganizationName = ConvertToUnSign.Convert(organizationBasic.OrganizationName);
            newOrg.Introduction      = organizationBasic.Introduction;
            newOrg.LogoUrl           = organizationBasic.LogoUrl;
            newOrg.Phone             = organizationBasic.Phone;
            newOrg.Email             = organizationBasic.Email;
            newOrg.Address           = organizationBasic.Address;
            newOrg.IsVerify          = false;
            newOrg.IsActive          = true;
            newOrg.Point             = 0;
            newOrg.CreatedDate       = DateTime.Now;

            using (var db = new Ws_DataContext())
            {
                db.Organizations.Add(newOrg);
                db.SaveChanges();
                return(GetOrganizationById(newOrg.OrganizationId));
            }
        }
Ejemplo n.º 2
0
        public Organization EditOrganization(CreateOrganization organizationBasic, string UserName)
        {
            try
            {
                int CurrenUser = 0;
                using (var db = new UserDAL())
                {
                    CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
                }
                using (var db = new Ws_DataContext())
                {
                    var currentOrg = db.Organizations.Find(CurrenUser);

                    currentOrg.OrganizationName = organizationBasic.OrganizationName;
                    currentOrg.OrganizationName = organizationBasic.OrganizationName;
                    currentOrg.Introduction     = organizationBasic.Introduction;
                    if (organizationBasic.LogoUrl != "" && organizationBasic.LogoUrl != null)
                    {
                        currentOrg.LogoUrl = organizationBasic.LogoUrl;
                    }
                    currentOrg.Phone   = organizationBasic.Phone;
                    currentOrg.Address = organizationBasic.Address;

                    db.SaveChanges();

                    return(GetOrganizationById(currentOrg.OrganizationId));
                }
            }
            catch (Exception)
            {
                return(null);
                //throw;
            }
        }
Ejemplo n.º 3
0
        public Thread UpdateThread(CreateThreadInfo thread, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            using (var db = new Ws_DataContext())
            {
                //Get current Thread To Edit
                var currentThread = db.Threads.Where(x => x.ThreadId == thread.ThreadId).SingleOrDefault();
                currentThread.Title            = thread.Title;
                currentThread.Content          = thread.Content;
                currentThread.ShortDescription = thread.ShortDescription;
                currentThread.UpdatedDate      = DateTime.Now;
                if (CurrenUser != currentThread.UserId)
                {
                    return(null);
                }
                else
                {
                    db.Threads.AddOrUpdate(currentThread);
                    db.SaveChanges();
                }
                return(currentThread);
            }
        }
Ejemplo n.º 4
0
 public bool ChangelikeStateForComment(int commentId, string UserName)
 {
     try
     {
         int CurrenUser = 0;
         using (var db = new UserDAL())
         {
             CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
         }
         using (var db = new Ws_DataContext())
         {
             //Check current like status.
             LikeCommentThread current = (
                 from p in db.LikeCommentThreads
                 where p.CommentId == commentId && p.UserId == CurrenUser
                 select p
                 ).SingleOrDefault();
             if (current != null)
             {
                 current.Status = !current.Status;
                 db.SaveChanges();
             }
             else
             {
                 db.LikeCommentThreads.Add(new LikeCommentThread()
                 {
                     CommentId = commentId, UserId = CurrenUser, Status = true
                 });
                 db.SaveChanges();
             }
             return(true);
         }
     }
     catch (Exception) { return(false); }
 }
Ejemplo n.º 5
0
        public List <BasicCommentThread> GetSubCommentInThreadById(int CommentId, string currentUserName)
        {
            int CurrenUser = 0;

            if (currentUserName != "")
            {
                using (var db = new UserDAL())
                {
                    CurrenUser = db.GetUserByUserNameOrEmail(currentUserName).UserID;
                }
            }
            List <BasicCommentThread> list = new List <BasicCommentThread>();

            using (var db = new Ws_DataContext())
            {
                try
                {
                    var listComment = db.SubCommentThread
                                      .Where(x => x.Status == true && x.CommentThreadId == CommentId)
                                      .Select(x => new { x.UserId, x.Ws_User.UserName, x.Ws_User.User_Information.ProfileImage, x.SubCommentThreadId, x.Content, x.CommentDate })
                                      .OrderByDescending(x => x.CommentDate).ToList();
                    foreach (var item in listComment)
                    {
                        BasicCommentThread bs = new BasicCommentThread();
                        bs.UserCommentedId   = item.UserId;
                        bs.UserCommentedName = item.UserName;
                        bs.UserImageProfile  = item.ProfileImage;
                        bs.CommentId         = item.SubCommentThreadId;
                        bs.Content           = item.Content;
                        if (CurrenUser == item.UserId)
                        {
                            bs.isDeleted = true;
                        }
                        else
                        {
                            bs.isDeleted = false;
                        }
                        if (DateTime.Now.Subtract(item.CommentDate).TotalHours <= 24 && DateTime.Now.Subtract(item.CommentDate).TotalHours >= 1)
                        {
                            bs.CommentedTime = Math.Round(DateTime.Now.Subtract(item.CommentDate).TotalHours, 0) + " Tiếng cách đây";
                        }
                        else if (DateTime.Now.Subtract(item.CommentDate).TotalHours > 24)
                        {
                            bs.CommentedTime = item.CommentDate.ToString("H:mm:ss dd/MM/yy");
                        }
                        else if (DateTime.Now.Subtract(item.CommentDate).Minutes == 0)
                        {
                            bs.CommentedTime = "Vừa xong";
                        }
                        else
                        {
                            bs.CommentedTime = DateTime.Now.Subtract(item.CommentDate).Minutes + " Phút cách đây";
                        }
                        list.Add(bs);
                    }
                }
                catch (Exception) { return(null); }
            }
            return(list);
        }
Ejemplo n.º 6
0
        public int CountUnreadConversation(string name)
        {
            int CurrentUser           = 0;
            int NumberOfUnreadMessage = 0;

            using (var db = new UserDAL())
            {
                CurrentUser = db.GetUserByUserNameOrEmail(name).UserID;
            }
            using (var db = new Ws_DataContext())
            {
                var list = (from p in db.Conversation
                            where p.CreatorId == CurrentUser || p.ReceiverId == CurrentUser
                            select new { p.CreatorId, p.ReceiverId, p.IsCreatorRead, p.IsReceiverRead }).ToList();
                foreach (var item in list)
                {
                    if (CurrentUser == item.CreatorId && item.IsCreatorRead == false)
                    {
                        NumberOfUnreadMessage++;
                    }
                    if (CurrentUser == item.ReceiverId && item.IsReceiverRead == false)
                    {
                        NumberOfUnreadMessage++;
                    }
                }
            }
            return(NumberOfUnreadMessage);
        }
Ejemplo n.º 7
0
        public Event AddNewEvent(CreateEventInfo eventInfo, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newEvent = CreateEmptyEvent();

            newEvent.CreatorID  = GetOrganizationById(CurrenUser).OrganizationId;
            newEvent.EventType  = eventInfo.EventType;
            newEvent.EventName  = eventInfo.EventName;
            newEvent.EEventName = ConvertToUnSign.Convert(newEvent.EventName);
            if (eventInfo.StartDate != "")
            {
                newEvent.Start_Date = DateTime.Parse(eventInfo.StartDate);
            }
            if (eventInfo.FinishDate != "")
            {
                newEvent.Finish_Date = DateTime.Parse(eventInfo.FinishDate);
            }
            newEvent.ShortDescription = eventInfo.ShortDescription;
            newEvent.Location         = eventInfo.Location;
            newEvent.ExpectedMoney    = eventInfo.ExpectedMoney;
            newEvent.Description      = eventInfo.Content;
            newEvent.Contact          = eventInfo.Contact;
            newEvent.VideoUrl         = eventInfo.VideoUrl;
            using (var db = new Ws_DataContext())
            {
                db.Events.Add(newEvent);
                db.SaveChanges();
                return(GetEventById(newEvent.EventID));
            }
        }
Ejemplo n.º 8
0
        public List <MessageBasicInfoDTO> GetAllMessageByConservationId(int id, string userName)
        {
            List <MessageBasicInfoDTO> messageList = new List <MessageBasicInfoDTO>();
            int UserId = 0;

            using (var db = new UserDAL())
            {
                UserId = db.GetUserByUserNameOrEmail(userName).UserID;
            }
            using (var db = new Ws_DataContext())
            {
                var list = db.Message.Where(x => x.ConservationId == id).ToList();
                foreach (var item in list)
                {
                    MessageBasicInfoDTO current = new MessageBasicInfoDTO();
                    //Set time
                    if (DateTime.Now.Subtract(item.CreatedDate).TotalHours <= 24 && DateTime.Now.Subtract(item.CreatedDate).TotalHours >= 1)
                    {
                        current.CreatedDate = Math.Round(DateTime.Now.Subtract(item.CreatedDate).TotalHours, 0) + " Tiếng cách đây";
                    }
                    else if (DateTime.Now.Subtract(item.CreatedDate).TotalHours > 24)
                    {
                        current.CreatedDate = item.CreatedDate.ToString("H:mm:ss dd/MM/yy");
                    }
                    else if (DateTime.Now.Subtract(item.CreatedDate).Minutes == 0)
                    {
                        current.CreatedDate = "Vừa xong";
                    }
                    else
                    {
                        current.CreatedDate = DateTime.Now.Subtract(item.CreatedDate).Minutes + " Phút cách đây";
                    }
                    //Set other atributes
                    current.CreatorImage = item.User.User_Information.ProfileImage;
                    current.CreatorName  = item.User.UserName;
                    current.Content      = item.Content;
                    messageList.Add(current);
                }
                //Update Is Read for message.
                var currentConversation = db.Conversation.Where(x => x.ConservationId == id).SingleOrDefault();
                if (UserId == currentConversation.CreatorId)
                {
                    currentConversation.IsCreatorRead = true;
                }
                if (UserId == currentConversation.ReceiverId)
                {
                    currentConversation.IsReceiverRead = true;
                }
                db.Conversation.AddOrUpdate(currentConversation);
                db.SaveChanges();
            }
            return(messageList);
        }
Ejemplo n.º 9
0
        public Thread AddNewThread(CreateThreadInfo thread, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newThread = CreateEmptyThread();

            newThread.UserId           = CurrenUser;
            newThread.Title            = thread.Title;
            newThread.Etitle           = ConvertToUnSign.Convert(thread.Title);
            newThread.Content          = thread.Content;
            newThread.ShortDescription = thread.ShortDescription;
            using (var db = new Ws_DataContext())
            {
                db.Threads.Add(newThread);
                db.SaveChanges();
                return(GetThreadById(newThread.ThreadId));
            }
        }
Ejemplo n.º 10
0
        public bool CheckUserIsLikedOrNot(int ThreadId, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            using (var db = new Ws_DataContext())
            {
                var isLike = (from p in db.LikeThreads
                              where p.ThreadId == ThreadId && p.UserId == CurrenUser && p.Status == true
                              select p).SingleOrDefault();
                if (isLike != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 11
0
        public List <ConservationBasicInfoDTO> GetAllConservationByUserIdAndStatus(string name, bool isRead)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(name).UserID;
            }

            List <ConservationBasicInfoDTO> ConservationList = new List <ConservationBasicInfoDTO>();

            using (var db = new Ws_DataContext())
            {
                var list = (from p in db.Conversation
                            where (p.CreatorId == CurrenUser || p.ReceiverId == CurrenUser)
                            select p).OrderByDescending(x => x.UpdatedTime).ToList();
                foreach (var item in list)
                {
                    if (CurrenUser == item.CreatorId && item.IsCreatorRead == isRead)
                    {
                        ConservationBasicInfoDTO current = new ConservationBasicInfoDTO();
                        //Set Image
                        if (item.ReceiverId == CurrenUser)
                        {
                            current.AvatarUrl   = item.Creator.User_Information.ProfileImage;
                            current.CreatorName = item.Creator.UserName;
                        }
                        else
                        {
                            current.AvatarUrl   = item.Receiver.User_Information.ProfileImage;
                            current.CreatorName = item.Receiver.UserName;
                        }
                        //Set Time
                        if (DateTime.Now.Subtract(item.UpdatedTime).TotalHours <= 24 && DateTime.Now.Subtract(item.UpdatedTime).TotalHours >= 1)
                        {
                            current.CreatedDate = Math.Round(DateTime.Now.Subtract(item.CreatedDate).TotalHours, 0) + " Tiếng cách đây";
                        }
                        else if (DateTime.Now.Subtract(item.UpdatedTime).TotalHours > 24)
                        {
                            current.CreatedDate = item.UpdatedTime.ToString("H:mm:ss dd/MM/yy");
                        }
                        else if (DateTime.Now.Subtract(item.CreatedDate).Minutes == 0)
                        {
                            current.CreatedDate = "Vừa xong";
                        }
                        else
                        {
                            current.CreatedDate = DateTime.Now.Subtract(item.UpdatedTime).Minutes + " Phút cách đây";
                        }
                        //Set other attributes
                        current.Title          = item.Title;
                        current.ConservationId = item.ConservationId;
                        ConservationList.Add(current);
                    }
                    if (CurrenUser == item.ReceiverId && item.IsReceiverRead == isRead)
                    {
                        ConservationBasicInfoDTO current = new ConservationBasicInfoDTO();
                        //Set Image
                        if (item.ReceiverId == CurrenUser)
                        {
                            current.AvatarUrl   = item.Creator.User_Information.ProfileImage;
                            current.CreatorName = item.Creator.UserName;
                        }
                        else
                        {
                            current.AvatarUrl   = item.Receiver.User_Information.ProfileImage;
                            current.CreatorName = item.Receiver.UserName;
                        }
                        //Set Time
                        if (DateTime.Now.Subtract(item.UpdatedTime).TotalHours <= 24 && DateTime.Now.Subtract(item.UpdatedTime).TotalHours >= 1)
                        {
                            current.CreatedDate = Math.Round(DateTime.Now.Subtract(item.CreatedDate).TotalHours, 0) + " Tiếng cách đây";
                        }
                        else if (DateTime.Now.Subtract(item.UpdatedTime).TotalHours > 24)
                        {
                            current.CreatedDate = item.UpdatedTime.ToString("H:mm:ss dd/MM/yy");
                        }
                        else if (DateTime.Now.Subtract(item.CreatedDate).Minutes == 0)
                        {
                            current.CreatedDate = "Vừa xong";
                        }
                        else
                        {
                            current.CreatedDate = DateTime.Now.Subtract(item.UpdatedTime).Minutes + " Phút cách đây";
                        }
                        //Set other attributes
                        current.Title          = item.Title;
                        current.ConservationId = item.ConservationId;
                        ConservationList.Add(current);
                    }
                }
                return(ConservationList);
            }
        }