Exemplo n.º 1
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); }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Change status of report to false
        /// </summary>
        /// <param name="isReportId"></param>
        /// <param name="reportType"></param>
        /// <returns></returns>
        public bool ChangeStatusOfReport(int isReportId, string reportType)
        {
            try
            {
                using (var db = new Ws_DataContext())
                {
                    List <Report> reports = db.Reports.Where(x => x.ReportTo == isReportId && x.Type == reportType && x.Status == true).ToList();
                    foreach (var report in reports)
                    {
                        report.Status = false;
                        db.Reports.AddOrUpdate(report);
                    }

                    db.SaveChanges();
                    //change success
                    return(true);
                }
            }
            catch (Exception)
            {
                //change false
                return(false);
                //throw;
            }
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
 public void UpdateTime(Conversation currentConservation)
 {
     using (var db = new Ws_DataContext())
     {
         db.Conversation.AddOrUpdate(currentConservation);
         db.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public void UpdateEvent(Event eventUpdate)
 {
     using (var db = new Ws_DataContext())
     {
         db.Events.AddOrUpdate(eventUpdate);
         db.SaveChanges();
     }
 }
Exemplo n.º 9
0
 public CommentThread AddNewComment(CommentThread comment)
 {
     using (var db = new Ws_DataContext())
     {
         var newComment = db.CommentThreads.Add(comment);
         db.SaveChanges();
         return(newComment);
     }
 }
Exemplo n.º 10
0
 public Message AddNewMessage(Message newMessage)
 {
     using (var db = new Ws_DataContext())
     {
         var returnedMessage = db.Message.Add(newMessage);
         db.SaveChanges();
         return(returnedMessage);
     }
 }
Exemplo n.º 11
0
 public Conversation AddNewConservation(Conversation newConservation)
 {
     using (var db = new Ws_DataContext())
     {
         var returnedConservation = db.Conversation.Add(newConservation);
         db.SaveChanges();
         return(returnedConservation);
     }
 }
Exemplo n.º 12
0
 public Ws_User AddNewUser(Ws_User newUser)
 {
     using (var db = new Ws_DataContext())
     {
         db.Ws_User.Add(newUser);
         db.SaveChanges();
         return(GetUserByUserNameOrEmail(newUser.Email));
     }
 }
Exemplo n.º 13
0
 public Report AddNewReport(Report newReport)
 {
     using (var db = new Ws_DataContext())
     {
         var currentReport = db.Reports.Add(newReport);
         db.SaveChanges();
         return(currentReport);
     }
 }
Exemplo n.º 14
0
 public SubCommentThread AddNewSubComment(SubCommentThread subComment)
 {
     using (var db = new Ws_DataContext())
     {
         var newComment = db.SubCommentThread.Add(subComment);
         db.SaveChanges();
         return(newComment);
     }
 }
Exemplo n.º 15
0
        public Ws_User UpdateUser(Ws_User User)
        {
            using (var db = new Ws_DataContext())
            {
                db.Ws_User.AddOrUpdate(User);
                db.SaveChanges();

                return(GetUserByUserNameOrEmail(User.UserName));
            }
        }
Exemplo n.º 16
0
        public EventType UpdateEventType(EventType type)
        {
            using (var db = new Ws_DataContext())
            {
                db.EventTypes.AddOrUpdate(type);
                db.SaveChanges();

                return(GetEventTypeById(type.EventTypeID));
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Add Event Album
        /// </summary>
        /// <param name="album"></param>
        /// <returns>eventAlbum</returns>
        public EventAlbumImage AddEventAlbum(EventAlbumImageDTO album)
        {
            var eventAlbum = CreateEmptyEventAlbum();

            eventAlbum.EventId  = album.EventId;
            eventAlbum.ImageUrl = album.ImageUrl;
            using (var db = new Ws_DataContext())
            {
                db.EventAlbum.Add(eventAlbum);
                db.SaveChanges();
                return(eventAlbum);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Add New Album
        /// </summary>
        /// <param name="album"></param>
        /// <returns>ThreadAlbumImage</returns>
        public ThreadAlbumImage AddNewAlbum(ThreadAlbumImageDTO album)
        {
            var emptyAlbum = CreateEmptyThreadAlbum();

            emptyAlbum.ThreadId = album.ThreadId;
            emptyAlbum.ImageUrl = album.ImageUrl;
            using (var db = new Ws_DataContext())
            {
                db.ThreadAlbum.Add(emptyAlbum);
                db.SaveChanges();
                return(emptyAlbum);
            }
        }
Exemplo n.º 20
0
 public bool UpdateUserInfo(UserBasicInfoDTO UserInfo, string userName)
 {
     try
     {
         using (var db = new Ws_DataContext())
         {
             var newInformation = db.User_Information.Where(x => x.Ws_User.UserName == userName).SingleOrDefault();
             if (UserInfo.FullName != null)
             {
                 newInformation.FullName  = UserInfo.FullName;
                 newInformation.EFullName = ConvertToUnSign.Convert(UserInfo.FullName);
             }
             if (UserInfo.Phone != null)
             {
                 newInformation.Phone = UserInfo.Phone;
             }
             if (UserInfo.Address != null)
             {
                 newInformation.UserAddress  = UserInfo.Address;
                 newInformation.EUserAddress = ConvertToUnSign.Convert(UserInfo.Address);
             }
             if (UserInfo.Country != null)
             {
                 newInformation.Country = UserInfo.Country;
             }
             if (UserInfo.Gender != null)
             {
                 newInformation.Gender = UserInfo.Gender;
             }
             if (UserInfo.DOB != "")
             {
                 newInformation.DoB = Convert.ToDateTime(UserInfo.DOB);
             }
             if (UserInfo.FacebookUri != null)
             {
                 newInformation.FacebookUrl = UserInfo.FacebookUri;
             }
             if (UserInfo.UserSignature != null)
             {
                 newInformation.UserSignature = UserInfo.UserSignature;
             }
             db.User_Information.AddOrUpdate(newInformation);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 21
0
 // Update Organization
 public Organization UpdateOrganization(Organization organ)
 {
     try
     {
         using (var db = new Ws_DataContext())
         {
             db.Organizations.AddOrUpdate(organ);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         //throw;
     }
     return(organ);
 }
Exemplo n.º 22
0
 // Update Thread
 public Thread UpdateThread(Thread thread)
 {
     try
     {
         using (var db = new Ws_DataContext())
         {
             db.Threads.AddOrUpdate(thread);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         //throw;
     }
     return(thread);
 }
Exemplo n.º 23
0
 public bool AddNewDonation(DonationDTO donationInfo)
 {
     using (var db = new Ws_DataContext())
     {
         var newDonate = db.Donations.Create();
         newDonate.UserId       = donationInfo.UserId;
         newDonate.EventId      = donationInfo.EventId;
         newDonate.TradeCode    = donationInfo.TradeCode;
         newDonate.DonatedMoney = donationInfo.DonatedMoney;
         newDonate.Content      = donationInfo.Content;
         newDonate.IsPublic     = donationInfo.IsPublic;
         newDonate.DonatedDate  = DateTime.Now;;
         db.Donations.Add(newDonate);
         db.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 24
0
 public bool CreateEventType(EventType type)
 {
     try
     {
         using (var db = new Ws_DataContext())
         {
             db.EventTypes.Add(type);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
         //throw;
     }
 }
Exemplo n.º 25
0
 public bool DeleteSubComment(int SubCommentId, string UserName)
 {
     using (var db = new Ws_DataContext())
     {
         var currentComment = (from p in db.SubCommentThread
                               where p.SubCommentThreadId == SubCommentId && p.Ws_User.UserName.Equals(UserName)
                               select p).FirstOrDefault();
         if (currentComment != null)
         {
             db.SubCommentThread.Remove(currentComment);
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 26
0
        public bool DeleteComment(int CommentId, string UserName)
        {
            using (var db = new Ws_DataContext())
            {
                var currentComment = (from p in db.CommentThreads
                                      where p.CommentThreadId == CommentId && p.Ws_User.UserName.Equals(UserName)
                                      select p).FirstOrDefault();
                if (currentComment != null)
                {
                    var subCommentInComment = (from p in db.SubCommentThread
                                               where p.CommentThreadId == currentComment.CommentThreadId
                                               select p).ToList();
                    if (subCommentInComment != null)
                    {
                        foreach (var item in subCommentInComment)
                        {
                            //Delete All SubComment First
                            db.SubCommentThread.Remove(item);
                        }
                    }
                    var LikeInComment = (from p in db.LikeCommentThreads
                                         where p.CommentId == CommentId
                                         select p).ToList();
                    if (LikeInComment != null)
                    {
                        foreach (var item in LikeInComment)
                        {
                            //Delete All SubComment First
                            db.LikeCommentThreads.Remove(item);
                        }
                    }

                    db.CommentThreads.Remove(currentComment);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 27
0
        public void AddNewEventTimeLine(CreateEventSchedule eventInfo, int eventId)
        {
            var newEventSchedule = CreateEmptyEventTimeLine();

            newEventSchedule.EventId = eventId;
            newEventSchedule.Content = eventInfo.Description;
            //newEventSchedule.FromDate =  DateTime.ParseExact(eventInfo.FromDate, "yyyy-MM-dd HH:mm:ss,fff",System.Globalization.CultureInfo.InvariantCulture);
            //newEventSchedule.ToDate = DateTime.ParseExact(eventInfo.ToDate, "yyyy-MM-dd HH:mm:ss,fff",System.Globalization.CultureInfo.InvariantCulture);
            if (eventInfo.FromDate != "")
            {
                newEventSchedule.FromDate = DateTime.Parse(eventInfo.FromDate);
            }
            if (eventInfo.ToDate != "")
            {
                newEventSchedule.ToDate = DateTime.Parse(eventInfo.ToDate);
            }
            using (var db = new Ws_DataContext())
            {
                db.ETimeLine.Add(newEventSchedule);
                db.SaveChanges();
            }
        }
Exemplo n.º 28
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));
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Delete orgaization with id
        /// </summary>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public bool DeleteOrganization(int orgId)
        {
            try
            {
                using (var db = new Ws_DataContext())
                {
                    Organization organization = db.Organizations.FirstOrDefault(x => x.OrganizationId == orgId);

                    if (organization != null)
                    {
                        db.Organizations.Remove(organization);
                        db.SaveChanges();
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
                //throw;
            }
        }