Thursday, August 23, 2018




using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Web;
using System.Web.Http;
using KlickSocialAPP.Helpers;
using KlickSocialAPP.Models;
using KlickSocialAPP.PushNotifications;
using KlickSocialAPP.Repository;

namespace KlickSocialAPP.Controllers
{
    public class ValuesController : ApiController
    {

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        [HttpPost]
        [ActionName("authenticateUser")]
        public dynamic authenticateUser(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            Pro_UserMaster_API Result = new UserRepository().AuthentucateUser(user.klickName, user.password, user.deviceId, user.deviceType);
            if (Result.mobileNumber == "-1" || Result.mobileNumber == "-2" || Result.mobileNumber == "-3")
            {
                //dicto = ServiceHelper.GetServiceJson(ServiceHelper.JsonType.Error, StatusConstants.Error, null, "Login Failed"); // msg as per client said           
                dicto.Add("status", 0);
                dicto.Add("message", Result.klickName);
            }
            else
            {
                dicto.Add("userDetail", Result);
                dicto.Add("status", "1");
                dicto.Add("message", "success");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("getUserProfile")]
        public dynamic getUserProfile(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            Pro_UserMaster_API Result = new UserRepository().GetUserById(user.mobileNumber);
            if (Result == null)
                dicto.Add("status", 0);
            else
            {
                dicto.Add("userDetail", Result);
                dicto.Add("status", "1");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("forgotPassword")]
        public dynamic forgotPassword(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string Result = Convert.ToString(new UserRepository().GetUserByUserNameEmailId(user.emailId));
            if (Result != "0")
            {
                Random rnd = new Random();
                string code = rnd.Next(1000, 10000).ToString();
                if (code.Length == 3)
                    code = code + "0";
                else if (code.Length == 2)
                    code = code + "00";

                Result = Convert.ToString(new UserRepository().UpdatePassword(Result, code));
                if (!string.IsNullOrEmpty(Result))
                {
                    //bool EmailStatus = EmailHelper.SendEmailForgotPassword(user.userName, user.emailId, code);
                    //if (EmailStatus == true)
                    //    dicto.Add("code", code);
                    //else
                    //    dicto.Add("Result", "Email Sending fail");

                    dicto.Add("mobileNumber", Result);
                    dicto.Add("status", "1");
                    dicto.Add("message", "success");
                }
            }
            else
            {
                dicto.Add("status", "0");
                dicto.Add("message", "EmailId doesn't exists");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("changePassword")]
        public dynamic changePassword(Pro_UserMaster_ChangePassword_API user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string Result = Convert.ToString(new UserRepository().ChangePassword(user));
            if (Result == user.mobileNumber)
            {
                dicto.Add("status", "1");
                dicto.Add("message", "success");
            }
            else if (Result == "2")
            {
                dicto.Add("status", "0");
                dicto.Add("message", "old password does not match.");
            }
            else if (Result == "0")
            {
                dicto.Add("status", "0");
                dicto.Add("message", "fail");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("UpdateNotification")]
        public dynamic UpdateNotification(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string Result = Convert.ToString(new UserRepository().UpdateNotification(user.mobileNumber, user.sendNotification));
            if (Result == user.mobileNumber)
                dicto.Add("status", "1");
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("updateLocation")]
        public dynamic updateLocation(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string Result = Convert.ToString(new UserRepository().UpdateLatLong(user.mobileNumber, user.latitude, user.longitude));
            if (Result == user.mobileNumber)
                dicto.Add("status", "1");
            else if (Result == "0")
            {
                dicto.Add("status", "0");
                dicto.Add("message", "user does not exists");
            }
            else
            {
                dicto.Add("status", "0");
                dicto.Add("message", "fail");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("registerUser")]
        public dynamic registerUser(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            Pro_UserMaster_API Result = new UserRepository().AddEditUser(user);
            if (Result.mobileNumber == user.mobileNumber)
            {
                if (!string.IsNullOrEmpty(user.profileImage))
                {
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Uploads/ProfilePicture/")))
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Uploads/ProfilePicture/"));
                    byte[] imageBytes = Convert.FromBase64String(user.profileImage);
                    MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
                    ms.Write(imageBytes, 0, imageBytes.Length);
                    Image image = Image.FromStream(ms, true);
                    image.Save(HttpContext.Current.Server.MapPath("~/Uploads/ProfilePicture/") + "ProfilePic_" + Result.mobileNumber + ".png");
                    Image imgthumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
                    imgthumb.Save(HttpContext.Current.Server.MapPath("~/Uploads/ProfilePicture/") + "Thumb_ProfilePic_" + Result.mobileNumber + ".png");

                    image.Dispose();
                    imgthumb.Dispose();
                }

                if (user.mode == "Insert")
                {   //-------------------Send Email with varfication code--------------                   
                    Random rnd = new Random();
                    string code = rnd.Next(1000, 10000).ToString();
                    if (code.Length == 3)
                        code = code + "0";
                    else if (code.Length == 2)
                        code = code + "00";

                    //bool EmailStatus = EmailHelper.SendEmailForVarificationCode(user.emailId, code, user.phoneNumber);
                    //if (EmailStatus == true)
                    dicto.Add("code", code);
                    //else
                    //    dicto.Add("Result", "Email Sending fail");                       
                    //-------------------End-------------------------------------------
                }

                dicto.Add("userDetail", Result);
                dicto.Add("status", "1");
                dicto.Add("message", "success");


            }
            else if (Result.mobileNumber == "-1")
            {
                dicto.Add("status", "0");
                dicto.Add("message", "Email already Exists");
            }
            else if (Result.mobileNumber == "-2")
            {
                dicto.Add("status", "0");
                dicto.Add("message", "MobileNumber already Exists");
            }
            else if (Result.mobileNumber == "-3")
            {
                dicto.Add("status", "0");
                dicto.Add("message", "KlickName already Exists");
            }
            else
            {
                dicto.Add("status", "0");
                dicto.Add("message", "fail");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("blockUnblockUser")]
        public dynamic blockUnblockUser(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().UpdateStatus(user.mobileNumber, user.contactNumber, Convert.ToInt16(user.friendStatus), Convert.ToInt16(user.isFriend));
            if (Result != null)
                dicto.Add("status", "1");
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("addFriend")]
        public dynamic addFriend(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_UserContact_API> Result = new UserContactRepository().AddContacts(user);
            if (Result != null)
            {
                dicto.Add("contacts", Result);
                dicto.Add("status", "1");
                dicto.Add("MessageType", 5);
                // PushHelper.SendPushNotificationAddFreind(user.mobileNumber);
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("getContacts")]
        public dynamic getContacts(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().GetContacts(user.mobileNumber, Convert.ToInt16(userContactStatus.Friend));
            if (Result != null)
            {
                dicto.Add("Friends", Result);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("getBlockedUsers")]
        public dynamic getBlockedUsers(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().GetContacts(user.mobileNumber, Convert.ToInt16(userContactStatus.Block));
            if (Result != null)
            {
                dicto.Add("Friends", Result);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("getExcludeUsers")]
        public dynamic getExcludeUsers(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().GetContacts(user.mobileNumber, Convert.ToInt16(userContactStatus.Exclude));
            if (Result != null)
            {
                dicto.Add("Friends", Result);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("excludeUser")]
        public dynamic excludeUser(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().UpdateStatus(user.mobileNumber, user.contactNumber, Convert.ToInt16(user.friendStatus), Convert.ToInt16(user.isFriend));
            if (Result != null)
                dicto.Add("status", "1");
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("removeFriend")]
        public dynamic removeFriend(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().UpdateStatus(user.mobileNumber, user.contactNumber, 0, 1);
            if (Result != null)
                dicto.Add("status", "1");
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("getFriends")]
        public dynamic getFriends(Pro_UserContactMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            var Result = new UserContactRepository().GetFriendsOnly(user.mobileNumber, user.contactNumber);
            if (Result != null)
            {
                dicto.Add("friendsList", Result);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("getCity")]
        public dynamic getCity(Pro_CityMaster city)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_CityMaster> Result = new UserRepository().GetCities(city.countryId);
            if (Result != null)
            {
                dicto.Add("Cities", Result);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("getCountry")]
        public dynamic getCountry()
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_CountryMaster_New> Result = new UserRepository().GetCountriesForAPI();
            if (Result != null)
            {
                dicto.Add("Countries", Result);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("uploadPost")]
        public dynamic uploadPost(Pro_PostMaster post)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            if (post.postId == 0)
            {
                int Result = Convert.ToInt32(new PostRepository().uploadPost(post));
                if (Result > 0)
                {
                    if (post.postType == 2)
                    {
                        byte[] imageByte = Convert.FromBase64String(post.thumbContent);
                        MemoryStream ms = new MemoryStream(imageByte, 0, imageByte.Length);
                        ms.Write(imageByte, 0, imageByte.Length);
                        Image image = Image.FromStream(ms, true);
                        image.Save(HttpContext.Current.Server.MapPath("~/Uploads/Posts/") + "Thumb_" + Result + ".png");
                        image.Dispose();
                    }
                    dicto.Add("postId", Result);
                    dicto.Add("status", 1);
                }
                else
                    dicto.Add("status", 0);
            }
            else if (post.postId > 0)
            {
                if (!string.IsNullOrEmpty(post.postContent))
                {
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Uploads/Posts/")))
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Uploads/Posts/"));

                    bool IsDataRemain;
                    byte[] imageBytes = Convert.FromBase64String(post.postContent);
                    if (post.IsUploadingEnd == true)
                    {
                        new Helpers.HelperFunctions().UploadFile(post.FileName, imageBytes, Convert.ToInt64(post.Offset), HttpContext.Current.Server.MapPath("~/Uploads/Posts/"));
                        IsDataRemain = false;
                        if (post.postType == 1)
                        {
                            Helpers.HelperFunctions.SaveThumbImage(HttpContext.Current.Server.MapPath("~/Uploads/Posts/") + post.FileName, 100, 100, "Thumb_");

                        }
                        //else if (post.postType == 2)
                        //{
                        //    byte[] imageByte = Convert.FromBase64String(post.thumbContent);
                        //    MemoryStream ms = new MemoryStream(imageByte, 0, imageByte.Length);
                        //    ms.Write(imageByte, 0, imageByte.Length);
                        //    Image image = Image.FromStream(ms, true);
                        //    image.Save(HttpContext.Current.Server.MapPath("~/Uploads/Posts/") + "Thumb_" + post.FileName + ".png");
                        //    image.Dispose();
                        //}
                    }
                    else
                        IsDataRemain = new Helpers.HelperFunctions().UploadFile(post.FileName, imageBytes, Convert.ToInt64(post.Offset), HttpContext.Current.Server.MapPath("~/Uploads/Posts/"));
                    dicto.Add("status", 1);

                }
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("getPosts")]
        public dynamic getPosts(Pro_PostMaster post)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();

            List<Pro_PostMaster_API> posts = new PostRepository().GetPostByMobileNumber(post.mobileNumber, post.isBefore, post.pageSize, post.postId, post.distanceType, post.distanceVal);
            if (posts.Count > 0)
            {
                dicto.Add("posts", posts);
                dicto.Add("status", "1");
            }
            else
            {
                dicto.Add("posts", posts);
                dicto.Add("status", "0");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("getPostById")]
        public dynamic getPostById(Pro_PostMaster_API post)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            Pro_PostMaster_API posts = new PostRepository().getPostById(post.postId, post.mobileNumber);
            if (posts != null)
            {
                dicto.Add("postDetail", posts);
                dicto.Add("status", "1");
            }
            else
                dicto.Add("status", "0");
            return dicto;
        }

        [HttpPost]
        [ActionName("deletePost")]
        public dynamic deletePost(Pro_PostMaster post)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_PostMaster> objPostList = new PostRepository().GetAllPostForDelete(post.postIds);
            foreach (Pro_PostMaster obj in objPostList)
            {
                if (obj.postType == 1)
                {
                    HelperFunctions.DeleteFile(HttpContext.Current.Server.MapPath("~/Uploads/Posts/" + obj.postId + ".png"));
                    HelperFunctions.DeleteFile(HttpContext.Current.Server.MapPath("~/Uploads/Posts/Thumb_" + obj.postId + ".png"));
                }
                else if (obj.postType == 2)
                {
                    HelperFunctions.DeleteFile(HttpContext.Current.Server.MapPath("~/Uploads/Posts/" + obj.postId + ".mp4"));
                }
            }
            string Result = Convert.ToString(new PostRepository().DeletePost(Convert.ToString(post.postIds)));
            if (!string.IsNullOrEmpty(Result))
                dicto.Add("status", 1);
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("addLike")]
        public dynamic addLike(Pro_PostMaster post)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string Result = Convert.ToString(new PostRepository().AddLike(post.postId, post.postBy));
            if (Result == "1")
            {
                dicto.Add("postId", post.postId);
                dicto.Add("status", 1);
                dicto.Add("message", "liked");
                PushHelper.SendPushNotificationLike(post.postId, post.postBy);
            }
            else if (Result == "-1")
            {
                dicto.Add("status", 1);
                dicto.Add("message", "disliked");
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("getAllLikes")]
        public dynamic getAllLikes(Pro_PostMaster post)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_LikeMaster_API> objPostList = new PostRepository().GetAllLikes(post.postId);
            if (objPostList != null)
            {
                dicto.Add("likeList", objPostList);
                dicto.Add("MessageType", 3);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("addComments")]
        public dynamic addComments(Pro_CommentMaster comment)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            Pro_CommentMaster_API Result = new CommentRepository().InsertComment(comment);
            if (Result != null)
            {
                dicto.Add("comments", Result);
                dicto.Add("status", 1);
                dicto.Add("MessageType", 4);
                PushHelper.SendPushNotificationComments(comment.postId, comment.commentedBy);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("deleteComment")]
        public dynamic deleteComment(Pro_CommentMaster comment)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            int Result = Convert.ToInt32(new CommentRepository().DeleteComment(comment.commentId));
            if (Result > 0)
                dicto.Add("status", 1);
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("getComments")]
        public dynamic getComments(Pro_CommentMaster comment)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_CommentMaster_API> objPro_FeedLikeUsers = new CommentRepository().GetComments(comment.postId, comment.commentId, comment.isBefore, comment.pageSize);
            if (objPro_FeedLikeUsers != null)
            {
                dicto.Add("comments", objPro_FeedLikeUsers);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("getPeopleAroundMe")]
        public dynamic getPeopleAroundMe(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_UserMaster_ArroundMe> objPro_Users = new UserRepository().AroundMe(user.mobileNumber, user.latitude, user.longitude, user.count, user.distance, user.distanceType);
            if (objPro_Users != null)
            {
                dicto.Add("users", objPro_Users);
                dicto.Add("status", 1);
            }
            else
            {
                dicto.Add("users", objPro_Users);
                dicto.Add("status", 0);
            }
            return dicto;
        }

        [HttpPost]
        [ActionName("sendPost")]
        public dynamic sendPost(Pro_MessageMaster msg)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string obj = Convert.ToString(new MessageRepository().SendPost(msg.messageFrom, msg.messageTo, msg.postId));
            if (obj == msg.messageFrom)
                dicto.Add("status", 1);
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("sendMessage")]
        public dynamic sendMessage(Pro_MessageMaster msg)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            if (msg.messageId == 0)
            {
                int Result = Convert.ToInt32(new MessageRepository().SaveChat(msg));
                if (Result > 0)
                {
                    if ((msg.messageType == 1 || msg.messageType == 2) && msg.thumbContent != "")
                    {
                        if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Uploads/Messages/")))
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Uploads/Messages/"));

                        byte[] imageBytes = Convert.FromBase64String(msg.thumbContent);
                        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
                        ms.Write(imageBytes, 0, imageBytes.Length);
                        Image image = Image.FromStream(ms, true);
                        image.Save(HttpContext.Current.Server.MapPath("~/Uploads/Messages/") + "Thumb_" + Result + ".png");
                        image.Dispose();
                    }
                    dicto.Add("messageId", Result);
                    dicto.Add("status", 1);
                    if (msg.messageType == 4 || msg.messageType == 3 || msg.messageType == 2 || msg.messageType == 1)
                        PushHelper.SendPushNotificationMessage(Result);

                    // ThreadPool.QueueUserWorkItem(report => PushHelper.SendPushNotificationMessage(Result));
                }
                else
                    dicto.Add("status", 0);
            }
            else if (msg.messageId > 0)
            {
                if (!string.IsNullOrEmpty(msg.messageContent))
                {
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Uploads/Messages/")))
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Uploads/Messages/"));

                    bool IsDataRemain;
                    byte[] imageBytes = Convert.FromBase64String(msg.messageContent);
                    if (msg.IsUploadingEnd == true)
                    {
                        new Helpers.HelperFunctions().UploadFile(msg.FileName, imageBytes, Convert.ToInt64(msg.Offset), HttpContext.Current.Server.MapPath("~/Uploads/Messages/"));
                        IsDataRemain = false;
                        if (msg.messageType == 4 || msg.messageType == 3 || msg.messageType == 2 || msg.messageType == 1)
                        {
                            ThreadPool.QueueUserWorkItem(report => PushHelper.SendPushNotificationMessage(msg.messageId));
                        }
                    }
                    else
                        IsDataRemain = new Helpers.HelperFunctions().UploadFile(msg.FileName, imageBytes, Convert.ToInt64(msg.Offset), HttpContext.Current.Server.MapPath("~/Uploads/Messages/"));

                    dicto.Add("status", 1);
                }
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("recieveMessage")]
        public dynamic recieveMessage(Pro_MessageMaster msg)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_MessageDetail> objPro_MessageDetail = new MessageRepository().GetMyNewMsg(msg.messageFrom, msg.messageTo, msg.messageId, msg.groupId);
            if (objPro_MessageDetail != null)
            {
                dicto.Add("messages", objPro_MessageDetail);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("getConversations")]
        public dynamic getConversations(Pro_MessageMaster msg)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_MessageHistoryDetail> objPro_MessageHistoryDetail = new MessageRepository().GetConversations(msg.messageFrom, msg.messageTo, msg.messageId);
            if (objPro_MessageHistoryDetail != null)
            {
                dicto.Add("messages", objPro_MessageHistoryDetail);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("getRecentMessages")]
        public dynamic getRecentMessages(Pro_MessageMaster msg)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_InboxScreen_Api> objPro_MessageDetail = new MessageRepository().GetRecentMsg(msg.messageTo, msg.messageId);
            if (objPro_MessageDetail != null)
            {
                dicto.Add("messages", objPro_MessageDetail);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("createGroup")]
        public dynamic createGroup(Pro_GroupMaster group)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            int obj = Convert.ToInt32(new GroupRepository().SaveGroup(group));
            if (obj == -1)
            {
                dicto.Add("message", "Group name already exist");
                dicto.Add("status", 0);
            }
            else if (obj > 0)
            {
                group.groupId = obj;
                ThreadPool.QueueUserWorkItem(report => PushHelper.SendNotifiationForCreateGroup(group));
                dicto.Add("groupId", obj);
                dicto.Add("status", 1);
            }
            else
            {
                dicto.Add("status", 0);
            } return dicto;
        }

        [HttpPost]
        [ActionName("getGroupList")]
        public dynamic getGroupList(Pro_GroupMaster group)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_GroupList> objPro_Detail = new GroupRepository().getGroupList(group);
            if (objPro_Detail != null)
            {
                dicto.Add("groupList", objPro_Detail);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }

        [HttpPost]
        [ActionName("getRecievedPosts")]
        public dynamic getRecievedPosts(Pro_MessageMaster msg)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            List<Pro_GetMessageDetail> objPro_GetMessageDetail = new MessageRepository().getRecievedPosts(msg.messageTo, msg.messageId);
            if (objPro_GetMessageDetail != null)
            {
                dicto.Add("RecievedPosts", objPro_GetMessageDetail);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;
        }
        [HttpPost]
        [ActionName("deleteAccount")]
        public dynamic deleteAccount(Pro_UserMaster user)
        {
            Dictionary<string, dynamic> dicto = new Dictionary<string, dynamic>();
            string objPro_Users = new UserRepository().deleteAccount(user.mobileNumber);
            if (objPro_Users != null)
            {
                dicto.Add("users", objPro_Users);
                dicto.Add("status", 1);
            }
            else
                dicto.Add("status", 0);
            return dicto;

        }
    }
}

No comments:

Post a Comment