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);
        }
        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);
        }
        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);
        }