public object GetMySentMessage(MessageCustomModel model)
        {
            List <MessageCustomModel> MessageListModel = new List <MessageCustomModel>();

            using (response = new Response())
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    try
                    {
                        response.success = true;
                        MessageListModel = dbcontext.tblMessages.Where(x => x.SenderId == model.SenderId && (model.ReceiverId == null || model.ReceiverId == 0 || x.tblMessageRecipients.FirstOrDefault(m => m.RecipientId == model.ReceiverId).RecipientId == model.ReceiverId))
                                           .Select(x => new MessageCustomModel
                        {
                            Id           = x.Id,
                            SenderId     = x.SenderId,
                            ReceiverName = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == model.ReceiverId).Name : "",
                            SenderName   = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == model.SenderId).Name : "",
                            MessageBody  = x.MessageBody,

                            IsActive    = x.IsActive,
                            CreatedDate = x.CreatedDate,
                        }).OrderBy(x => x.Id).ToList();

                        return(MessageListModel);
                    }
                    catch (Exception ex)
                    {
                        response.success = false;
                        response.message = ex.Message;
                        return(response);
                    }
                }
            }
        }
        public OperationStatus SubmitMessage(MessageCustomModel model)
        {
            OperationStatus status = OperationStatus.Error;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    using (dbcontext = new ChatApplicationEntities())
                    {
                        if (model.Id == 0)
                        {
                            tblMessage _addMessage = new tblMessage
                            {
                                SenderId        = model.SenderId,
                                Subject         = model.Subject,
                                MessageBody     = model.MessageBody,
                                ParentMessageId = model.ParentMessageId,
                                IsActive        = true,
                                CreatedDate     = DateTime.Now
                            };
                            dbcontext.tblMessages.Add(_addMessage);
                            dbcontext.SaveChanges();
                            int messageid = _addMessage.Id;

                            tblMessageRecipient _addMessageRecipient = new tblMessageRecipient
                            {
                                MessageId   = messageid,
                                RecipientId = model.ReceiverId,
                                IsActive    = true,
                                CreatedDate = DateTime.Now,
                            };

                            dbcontext.tblMessageRecipients.Add(_addMessageRecipient);
                            dbcontext.SaveChanges();

                            status = OperationStatus.Success;
                            ts.Complete();
                        }
                        else
                        {
                            status = OperationStatus.Duplicate;
                            //ts.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    dbcontext.Dispose();
                    status = OperationStatus.Exception;
                    ts.Dispose();
                    throw ex;
                }
            }
            return(status);
        }
        /// <summary>
        /// method is used for validate application users
        /// </summary>
        /// <param name="Logininfo"></param>
        /// <returns></returns>
        public object GetLoginUser(LoginUserModel Logininfo)
        {
            APIResponse       _response        = new APIResponse();
            LoggedInUserModel lgAppUserDetails = new LoggedInUserModel();
            object            objLgAppUserDetails;

            try
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    Logininfo.UserName = Logininfo.UserName.ToLower();
                    tblApplicationUser lgDetail = dbcontext.tblApplicationUsers.FirstOrDefault(x => x.UserName.ToLower() == Logininfo.UserName && x.IsDeleted == false);

                    if (lgDetail != null)
                    {
                        if (lgDetail.Password == Logininfo.Password)
                        {
                            lgAppUserDetails.ApplicationUserId = lgDetail.ApplicationUserId;
                            lgAppUserDetails.IsActive          = lgDetail.IsActive;
                            lgAppUserDetails.UserIdentityKey   = lgDetail.UserIdentityKey;
                            lgAppUserDetails.success           = true;
                            lgAppUserDetails.ErrorMessage      = "User Authenticated!!";
                            lgAppUserDetails.Name     = lgDetail.Name == null ? "" : lgDetail.Name;
                            lgAppUserDetails.EmailId  = lgDetail.EmailId;
                            lgAppUserDetails.MobileNo = lgAppUserDetails.MobileNo;

                            _response.Message  = "User Authenticated!!";
                            _response.IsSucess = true;
                        }
                        else
                        {
                            lgAppUserDetails.ErrorMessage = "Invalid password!!";
                            _response.Message             = "Invalid password!!";
                            _response.IsSucess            = false;
                        }
                    }
                    else
                    {
                        lgAppUserDetails.ErrorMessage = "Invalid username!!";
                        _response.Message             = "Invalid username!!";
                        _response.IsSucess            = false;
                    }
                }
            }
            catch (Exception ex)
            {
                lgAppUserDetails              = null;
                objLgAppUserDetails           = null;
                dbcontext                     = null;
                lgAppUserDetails.ErrorMessage = ex.Message.ToString();
            }
            objLgAppUserDetails = lgAppUserDetails;
            return(objLgAppUserDetails);
        }
        /// <summary>
        /// method is used to get my recivied messages
        /// </summary>
        /// <param name="MessageModel"></param>
        /// <returns></returns>
        public object GetMyReciviedMessage(MessageRecipientCustomModel model)
        {
            List <MessageRecipientCustomModel> MessageListModel = new List <MessageRecipientCustomModel>();

            using (response = new Response())
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    try
                    {
                        response.success = true;
                        MessageListModel = dbcontext.tblMessageRecipients.Where(x => x.RecipientId == model.RecipientId && (model.SenderId == null || model.SenderId == 0 || x.tblMessage.SenderId == model.SenderId))
                                           .Select(x => new MessageRecipientCustomModel
                        {
                            MessageId          = x.MessageId,
                            MessageRecipientId = x.MessageRecipientId,
                            RecipientId        = x.RecipientId,
                            SenderId           = x.tblMessage != null ? x.tblMessage.SenderId : 0,
                            ReceiverName       = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == model.RecipientId).Name : "",
                            SenderName         = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == model.SenderId).Name : "",
                            Message            = x.tblMessage != null ? x.tblMessage.MessageBody : "",

                            IsActive    = x.IsActive,
                            CreatedDate = x.CreatedDate,
                        }).OrderBy(x => x.MessageRecipientId).ToList();

                        return(MessageListModel);

                        //                     var query = dbcontext.tblMessageRecipients // your starting point - table in the "from" statement
                        //.Join(dbcontext.tblMessages, // the source table of the inner join
                        //   post => post.MessageId,        // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                        //   meta => meta.Id,   // Select the foreign key (the second part of the "on" clause)
                        //   (post, meta) => new { Post = post, Meta = meta }) // selection
                        //.Where(postAndMeta => postAndMeta.Post.RecipientId == model.RecipientId && postAndMeta.Meta.SenderId == model.SenderId)    // where statement
                        //.Select(m => new MessageRecipientCustomModel
                        //{
                        //    MessageId = m.Post.MessageId,
                        //    RecipientId = m.Post.RecipientId,
                        //    SenderId = m.Meta.SenderId
                        //}
                        //).ToList();

                        //                     return query;
                    }
                    catch (Exception ex)
                    {
                        response.success = false;
                        response.message = ex.Message;
                        return(response);
                    }
                }
            }
        }
        public OperationStatus AddFriendRequest(ApplicationFriendAssociationModel objAssociation)
        {
            OperationStatus status = OperationStatus.Error;

            try
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    if (objAssociation.ApplicationFriendAssociationId == 0)
                    {
                        var rs = dbcontext.tblApplicationFriendAssociations.FirstOrDefault(x => x.MemberId == objAssociation.MemberId && x.FriendId == objAssociation.FriendId && x.IsDeleted == false);
                        if (rs == null)
                        {
                            tblApplicationFriendAssociation _addAssociation = new tblApplicationFriendAssociation
                            {
                                MemberId     = objAssociation.MemberId,
                                FriendId     = objAssociation.FriendId,
                                RequestBy    = objAssociation.RequestBy,
                                IsConfirm    = 2,
                                IsActive     = true,
                                IsDeleted    = false,
                                CreatedDate  = DateTime.Now,
                                CreatedBy    = objAssociation.CreatedBy,
                                ModifiedDate = DateTime.Now,
                                ModifiedBy   = objAssociation.ModifiedBy,
                            };
                            dbcontext.tblApplicationFriendAssociations.Add(_addAssociation);
                            dbcontext.SaveChanges();

                            status = OperationStatus.Success;
                        }
                        else
                        {
                            status = OperationStatus.Duplicate;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dbcontext.Dispose();
                status = OperationStatus.Exception;
                throw ex;
            }

            return(status);
        }
Пример #6
0
        public OperationStatus ForgotPassword(ForgotPasswordCustomModel model)
        {
            OperationStatus status = OperationStatus.Error;

            try
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    var rs = dbcontext.tblApplicationUsers.FirstOrDefault(x => x.UserName == model.UserName);
                    if (rs != null)
                    {
                        string from = "*****@*****.**";  //any valid GMail ID
                        string to   = Convert.ToString(rs.EmailId); //any valid GMail ID
                        using (MailMessage mail = new MailMessage(from, to))
                        {
                            mail.Subject = "SFS Management Forgot Password";
                            mail.Body    = "Dear " + rs.Name + " <br><br>Please use this password to login: "******"<br><br>Thanks,<br>Team";

                            mail.IsBodyHtml = true;
                            SmtpClient smtp = new SmtpClient();
                            smtp.Host = "smtp.gmail.com";
                            smtp.Port = 587;
                            smtp.UseDefaultCredentials = false;
                            smtp.Credentials           = new System.Net.NetworkCredential
                                                             ("*****@*****.**", "shally123");// Enter seders User name and password
                            smtp.EnableSsl = true;
                            smtp.Send(mail);

                            status = OperationStatus.Success;
                        }
                    }
                    else
                    {
                        status = OperationStatus.Duplicate;
                    }
                }
            }
            catch (Exception ex)
            {
                dbcontext.Dispose();
                status = OperationStatus.Exception;
                throw ex;
            }

            return(status);
        }
        public object MyFriendList(int MemberId)
        {
            IList <ApplicationFriendAssociationModel> MemberListModel = new List <ApplicationFriendAssociationModel>();

            using (response = new Response())
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    try
                    {
                        response.success = true;
                        MemberListModel  = dbcontext.tblApplicationFriendAssociations.Where(x => x.FriendId == MemberId && x.IsConfirm == 1)
                                           .Select(x => new ApplicationFriendAssociationModel
                        {
                            ApplicationFriendAssociationId = x.ApplicationFriendAssociationId,
                            MemberId      = x.FriendId,
                            MemberName    = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == x.FriendId).Name : "",
                            EmailId       = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == x.MemberId).EmailId : "",
                            MobileNo      = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == x.MemberId).MobileNo : "",
                            FriendId      = x.MemberId,
                            FriendName    = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == x.MemberId).Name : "",
                            RequestBy     = x.RequestBy,
                            RequestByName = x.tblMember != null ? dbcontext.tblMembers.FirstOrDefault(m => m.MemberId == x.RequestBy).Name : "",
                            IsConfirm     = x.IsConfirm,
                            IsActive      = x.IsActive,
                            IsDeleted     = x.IsDeleted,
                            CreatedBy     = x.CreatedBy,
                            CreatedDate   = x.CreatedDate,
                            ModifiedBy    = x.ModifiedBy,
                            ModifiedDate  = x.ModifiedDate,
                        }).OrderByDescending(x => x.MemberId).ToList();

                        return(MemberListModel);
                    }
                    catch (Exception ex)
                    {
                        response.success = false;
                        response.message = ex.Message;
                        return(response);
                    }
                }
            }
        }
        public object GetApplicationMemberList(MemberCustomModel objMemberModel)
        {
            IList <MemberCustomModel> MemberListModel = new List <MemberCustomModel>();

            using (response = new Response())
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    try
                    {
                        response.success = true;
                        MemberListModel  = dbcontext.tblMembers.Where(x => x.IsDeleted == false)
                                           .Select(x => new MemberCustomModel
                        {
                            MemberId     = x.MemberId,
                            Name         = x.Name,
                            EmailId      = x.EmailId,
                            MobileNo     = x.MobileNo,
                            MotherName   = x.MotherName,
                            FatherName   = x.FatherName,
                            Address      = x.Address,
                            DateOfBirth  = x.DateOfBirth,
                            Gender       = x.Gender,
                            Image        = x.Image,
                            IsActive     = x.IsActive,
                            IsDeleted    = x.IsDeleted,
                            CreatedBy    = x.CreatedBy,
                            CreatedDate  = x.CreatedDate,
                            ModifyBy     = x.ModifyBy,
                            ModifiedDate = x.ModifiedDate,
                        }).OrderByDescending(x => x.MemberId).ToList();

                        return(MemberListModel);
                    }
                    catch (Exception ex)
                    {
                        response.success = false;
                        response.message = ex.Message;
                        return(response);
                    }
                }
            }
        }
 public object GetOurOldMessage(int SenderId, int ReceiverId)
 {
     using (response = new Response())
     {
         using (dbcontext = new ChatApplicationEntities())
         {
             try
             {
                 response.success = true;
                 var MessageList = dbcontext.USP_OurOldMessage(SenderId, ReceiverId).ToList();
                 return(MessageList);
             }
             catch (Exception ex)
             {
                 response.success = false;
                 response.message = ex.Message;
                 return(response);
             }
         }
     }
 }
        public OperationStatus ActionOnFriendRequest(ApplicationFriendAssociationModel objAssociation)
        {
            OperationStatus status = OperationStatus.Error;

            try
            {
                using (dbcontext = new ChatApplicationEntities())
                {
                    if (objAssociation.ApplicationFriendAssociationId != 0 && objAssociation.Status != string.Empty)
                    {
                        var rs = dbcontext.tblApplicationFriendAssociations.FirstOrDefault(x => x.ApplicationFriendAssociationId == objAssociation.ApplicationFriendAssociationId && x.IsActive == true && x.IsDeleted == false);
                        if (rs != null)
                        {
                            rs.IsConfirm    = objAssociation.Status == "Accept" ? 1 : 3;
                            rs.CreatedDate  = DateTime.Now;
                            rs.CreatedBy    = objAssociation.CreatedBy;
                            rs.ModifiedDate = DateTime.Now;
                            rs.ModifiedBy   = objAssociation.ModifiedBy;

                            dbcontext.SaveChanges();

                            status = OperationStatus.Success;
                        }
                        else
                        {
                            status = OperationStatus.Duplicate;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dbcontext.Dispose();
                status = OperationStatus.Exception;
                throw ex;
            }

            return(status);
        }
        /// <summary>
        /// This method is used to save new members
        /// </summary>
        /// <returns></returns>
        public OperationStatus SaveApplicationUser(ApplicationUserModel applicationUserModel)
        {
            OperationStatus status = OperationStatus.Error;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    using (dbcontext = new ChatApplicationEntities())
                    {
                        if (applicationUserModel.ApplicationUserId == 0)
                        {
                            var rs = dbcontext.tblApplicationUsers.FirstOrDefault(x => x.UserName == applicationUserModel.UserName && x.IsDeleted == false);
                            if (rs == null)
                            {
                                tblMember _addMember = new tblMember
                                {
                                    Name     = applicationUserModel.Name,
                                    EmailId  = applicationUserModel.EmailId,
                                    MobileNo = applicationUserModel.MobileNo,

                                    IsActive     = true,
                                    IsDeleted    = false,
                                    CreatedDate  = DateTime.Now,
                                    CreatedBy    = applicationUserModel.CreatedBy,
                                    ModifiedDate = DateTime.Now,
                                    ModifyBy     = applicationUserModel.ModifyBy,
                                };
                                dbcontext.tblMembers.Add(_addMember);
                                dbcontext.SaveChanges();
                                int userid = _addMember.MemberId;

                                tblApplicationUser _applicationUserinfo = new tblApplicationUser
                                {
                                    Name            = applicationUserModel.Name,
                                    EmailId         = applicationUserModel.EmailId,
                                    MobileNo        = applicationUserModel.MobileNo,
                                    UserIdentityKey = userid,
                                    UserName        = applicationUserModel.UserName,
                                    Password        = applicationUserModel.Password,

                                    IsActive     = true,
                                    IsDeleted    = false,
                                    CreatedDate  = DateTime.Now,
                                    CreatedBy    = applicationUserModel.CreatedBy,
                                    ModifiedDate = DateTime.Now,
                                    ModifyBy     = applicationUserModel.ModifyBy,
                                };

                                dbcontext.tblApplicationUsers.Add(_applicationUserinfo);
                                dbcontext.SaveChanges();

                                status = OperationStatus.Success;
                                ts.Complete();
                            }
                            else
                            {
                                status = OperationStatus.Duplicate;
                                //ts.Dispose();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    dbcontext.Dispose();
                    status = OperationStatus.Exception;
                    ts.Dispose();
                    throw ex;
                }
            }
            return(status);
        }