public dynamic UpdateCallingRequest(decimal amount, PaymentModel pM, string id)
 {
     using (LystenEntities db = new LystenEntities())
     {
         var obj = db.Calling_Request.Where(x => x.Id == pM.CallingRequestId).FirstOrDefault();
         obj.TotalCallingTime = pM.TotalCallingTime;
         obj.TotalAmount      = amount + obj.TotalAmount;
         db.Entry(obj).State  = EntityState.Modified;
         db.SaveChanges();
         return(obj);
     }
 }
示例#2
0
 public object ActivedeActiveCallingPrice(int id)
 {
     using (LystenEntities db = new LystenEntities())
     {
         var Event = db.CallingPriceMasters.Where(x => x.Id == id).FirstOrDefault();
         if (Event.IsActive == true)
         {
             Event.IsActive = false;
         }
         else
         {
             Event.IsActive = true;
         }
         db.Entry(Event).State = EntityState.Modified;
         db.SaveChanges();
         return(new { Id = 1, Status = Event.IsActive });
     }
 }
示例#3
0
 public dynamic ActiveDeActiveCategory(int id)
 {
     using (LystenEntities db = new LystenEntities())
     {
         var Categories = db.Categories.Where(x => x.Id == id).FirstOrDefault();
         if (Categories.IsActive == true)
         {
             Categories.IsActive = false;
         }
         else
         {
             Categories.IsActive = true;
         }
         db.Entry(Categories).State = EntityState.Modified;
         db.SaveChanges();
         return(new { Id = 1, Status = Categories.IsActive });
     }
 }
示例#4
0
 public object ActiveDeActiveUser(int id)
 {
     using (LystenEntities db = new LystenEntities())
     {
         var User = db.User_Master.Where(x => x.Id == id).FirstOrDefault();
         if (User.IsActive == true)
         {
             User.IsActive = false;
         }
         else
         {
             User.IsActive = true;
         }
         db.Entry(User).State = EntityState.Modified;
         db.SaveChanges();
         return(new { Id = 1, Status = User.IsActive });
     }
 }
        public dynamic SaveEvents(EventViewModel uM)
        {
            IdModel IM = new IdModel();


            using (LystenEntities db = new LystenEntities())
            {
                var data = DateTimeOffset.Parse(uM.CreatedDate);

                if (uM.Id > 0)
                {
                    Event qs = db.Events.Where(x => x.Id == uM.Id).Include(x => x.Category).FirstOrDefault();
                    qs.Title           = uM.Title;
                    qs.Description     = uM.Description;
                    qs.CategoryId      = uM.CategoryId;
                    qs.Location        = uM.Location;
                    qs.CreatedDate     = data.UtcDateTime;
                    qs.Image           = uM.Image;
                    qs.IsActive        = true;
                    db.Entry(qs).State = EntityState.Modified;
                    db.SaveChanges();
                    IM.Id = qs.Id;
                    return(IM);
                }
                else
                {
                    Event qs = new Event()
                    {
                        Title       = uM.Title,
                        Description = uM.Description,
                        CategoryId  = uM.CategoryId,
                        Location    = uM.Location,
                        CreatedDate = data.UtcDateTime,
                        Image       = uM.Image,
                        CreatorId   = uM.UserId,
                        IsActive    = true,
                    };
                    db.Events.Add(qs);
                    db.SaveChanges();
                    IM.Id = qs.Id;
                    return(IM);
                }
            }
        }
示例#6
0
 public dynamic Changepassword(UserModel objcurpwd)
 {
     using (LystenEntities db = new LystenEntities())
     {
         var         paswrdenc = SecutiryServices.EncodePasswordToBase64(objcurpwd.Currentpassword);
         User_Master result    = (from um in db.User_Master
                                  where um.Id == objcurpwd.Id &&
                                  um.Password == paswrdenc
                                  select um
                                  ).FirstOrDefault();
         if (result != null)
         {
             result.Password        = SecutiryServices.EncodePasswordToBase64(objcurpwd.Newpassword);
             db.Entry(result).State = EntityState.Modified;
             db.SaveChanges();
             return("Success");
         }
         else
         {
             return("Invalid Password.");
         }
     }
 }
        public dynamic UpdateGroup(GroupViewModel GVM)
        {
            string baseURL = HttpContext.Current.Request.Url.Authority;

            baseURL += (WebConfigurationManager.AppSettings["groupimagepath"]).Replace("~", "");
            GroupViewModel data = new GroupViewModel();
            Group          G    = new Group();

            using (LystenEntities db = new LystenEntities())
            {
                G              = db.Groups.Where(x => x.Id == GVM.Id).FirstOrDefault();
                G.Name         = GVM.Name;
                G.ModifiedDate = System.DateTime.Now;
                if (GVM.Image != null)
                {
                    data.Image        = baseURL + GVM.Image;
                    G.Image           = GVM.Image;
                    db.Entry(G).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    data.Image = baseURL + GVM.Image;
                }
                data = AutoMapper.Mapper.Map <Group, GroupViewModel>(G);
                if (G.Image == null || G.Image == "")
                {
                    data.Image = "";
                }
                else
                {
                    data.Image = baseURL + GVM.Image;
                }
                return(data);
            }
        }
示例#8
0
 public dynamic SaveEvent(Event CM)
 {
     using (LystenEntities db = new LystenEntities())
     {
         if (CM.Id > 0)
         {
             var Event = db.Events.Where(x => x.Id == CM.Id).FirstOrDefault();
             Event.ModifiedDate    = System.DateTime.Now;
             Event.Description     = CM.Description;
             Event.Title           = CM.Title;
             Event.CategoryId      = CM.CategoryId;
             Event.IsActive        = CM.IsActive;
             Event.Location        = CM.Location;
             db.Entry(Event).State = EntityState.Modified;
             db.SaveChanges();
             return(new { Id = CM.Id, Status = "Update" });
         }
         else
         {
             if (db.Events.Any(x => x.Title == (CM.Title).Trim()))
             {
                 CM.Id = db.Events.Where(x => x.Title == (CM.Title).Trim()).Select(x => x.Id).FirstOrDefault();
                 return(new { Id = CM.Id, Status = "Exists" });
             }
             else
             {
                 CM.IsActive    = true;
                 CM.CreatedDate = System.DateTime.Now;
                 CM.CreatedBy   = 1;
                 db.Events.Add(CM);
                 db.SaveChanges();
                 return(new { Id = CM.Id, Status = "Insert" });
             }
         }
     }
 }
示例#9
0
 public dynamic SaveCallingPriceMaster(CallingPriceMaster viewModel)
 {
     using (LystenEntities db = new LystenEntities())
     {
         if (viewModel.Id > 0)
         {
             var callingPrice = db.CallingPriceMasters.Where(x => x.Id == viewModel.Id).FirstOrDefault();
             callingPrice.ModifiedDate    = System.DateTime.Now;
             callingPrice.Name            = viewModel.Name;
             callingPrice.Description     = viewModel.Description;
             callingPrice.Price           = viewModel.Price;
             callingPrice.Time            = viewModel.Time;
             callingPrice.ModifiedDate    = DateTime.Now;
             db.Entry(callingPrice).State = EntityState.Modified;
             db.SaveChanges();
             return(new { Id = viewModel.Id, Status = "Update" });
         }
         else
         {
             if (db.Categories.Any(x => x.Name == (viewModel.Name).Trim()))
             {
                 viewModel.Id = db.Categories.Where(x => x.Name == (viewModel.Name).Trim()).Select(x => x.Id).FirstOrDefault();
                 return(new { Id = viewModel.Id, Status = "Exists" });
             }
             else
             {
                 viewModel.IsActive     = true;
                 viewModel.CreatedDate  = DateTime.Now;
                 viewModel.ModifiedDate = DateTime.Now;
                 db.CallingPriceMasters.Add(viewModel);
                 db.SaveChanges();
                 return(new { Id = viewModel.Id, Status = "Insert" });
             }
         }
     }
 }
示例#10
0
        public object MarkAsVerified(int id)
        {
            using (LystenEntities db = new LystenEntities())
            {
                var User = db.User_Master.Where(x => x.Id == id).FirstOrDefault();
                if (User.IsVerified == null || User.IsVerified == false)
                {
                    User.IsVerified = true;
                }

                db.Entry(User).State = EntityState.Modified;
                db.SaveChanges();
                try
                {
                    Helpers.EmailHelper.SendEmail(User.Email, User.UserName, User.Password);
                }
                catch
                {
                }


                return(new { Id = 1, Status = User.IsActive });
            }
        }
示例#11
0
 public dynamic SaveUser(UserModel objUM)
 {
     using (LystenEntities db = new LystenEntities())
     {
         if (objUM.Id > 0)
         {
             var user     = db.User_Master.Where(x => x.Id == objUM.Id).FirstOrDefault();
             var sendflag = false;
             if (user.Password != objUM.Password)
             {
                 sendflag = true;
             }
             //user.Email = objUM.Email;
             user.Password        = objUM.Password;
             user.Address         = objUM.Address;
             user.CountryId       = objUM.Country;
             user.StateId         = objUM.State;
             user.CityId          = objUM.City;
             user.Phone           = objUM.Phone;
             user.Mobile          = objUM.Mobile;
             user.Displayname     = objUM.Displayname;
             user.IsActive        = true;
             user.Modifydate      = System.DateTime.Now;
             db.Entry(user).State = EntityState.Modified;
             db.SaveChanges();
             if (sendflag == true)
             {
                 ES.SendToUser(user);
             }
             return(new { Id = user.Id, Status = "Update" });
         }
         else
         {
             if (db.User_Master.Any(x => x.Email == (objUM.Email).Trim()))
             {
                 objUM.Id = db.User_Master.Where(x => x.Email == (objUM.Email).Trim()).Select(x => x.Id).FirstOrDefault();
                 return(new { Id = objUM.Id, Status = "Exists" });
             }
             else
             {
                 User_Master user = new User_Master();
                 user.Email       = objUM.Email;
                 user.Password    = objUM.Password;
                 user.Address     = objUM.Address;
                 user.CountryId   = objUM.Country;
                 user.StateId     = objUM.State;
                 user.CityId      = objUM.City;
                 user.Phone       = objUM.Phone;
                 user.Mobile      = objUM.Mobile;
                 user.Displayname = objUM.Displayname;
                 user.IsActive    = true;
                 user.Createdate  = System.DateTime.Now;
                 user.Modifydate  = System.DateTime.Now;
                 user.Createdby   = 1;
                 db.User_Master.Add(user);
                 db.SaveChanges();
                 ES.SendToUser(user);
                 return(new { Id = user.Id, Status = "Insert" });
             }
         }
     }
 }
        public dynamic messagerequest(MessageRequestModel MM)
        {
            using (LystenEntities db = new LystenEntities())
            {
                MessageRequest MR = new MessageRequest();
                if (db.MessageRequests.Any(x => x.FromUserId == MM.MRUserId && x.ToUserId == MM.UserId || x.FromUserId == MM.UserId && x.ToUserId == MM.MRUserId))
                {
                    MR = db.MessageRequests.Where(x => x.FromUserId == MM.MRUserId && x.ToUserId == MM.UserId || x.FromUserId == MM.UserId && x.ToUserId == MM.MRUserId).FirstOrDefault();
                    if (MM.IsAccept == 0)
                    {
                        MR.IsAccept        = false;
                        MR.IsReject        = true;
                        MR.IsRequested     = false;
                        db.Entry(MR).State = EntityState.Modified;
                        db.SaveChanges();

                        if (MR.User_Master.DeviceToken != null)
                        {
                            if (MR.User_Master.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                        }
                        else if (MR.User_Master1.DeviceToken != null)
                        {
                            if (MR.User_Master1.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                        }
                    }
                    else
                    {
                        MR.IsAccept        = true;
                        MR.IsReject        = false;
                        MR.IsRequested     = false;
                        db.Entry(MR).State = EntityState.Modified;
                        db.SaveChanges();
                        if (MR.User_Master.DeviceToken != null)
                        {
                            if (MR.User_Master.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                        }
                        else if (MR.User_Master1.DeviceToken != null)
                        {
                            if (MR.User_Master1.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                        }
                    }
                }
                else
                {
                    if (MM.IsAccept == 0)
                    {
                        MR.FromUserId  = MM.MRUserId;
                        MR.ToUserId    = MM.UserId;
                        MR.IsAccept    = false;
                        MR.IsReject    = true;
                        MR.IsRequested = false;
                        db.MessageRequests.Add(MR);
                        db.SaveChanges();
                        if (MR.User_Master.DeviceToken != null)
                        {
                            if (MR.User_Master.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                        }
                        else if (MR.User_Master1.DeviceToken != null)
                        {
                            if (MR.User_Master1.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                        }
                    }
                    else
                    {
                        MR.FromUserId  = MM.MRUserId;
                        MR.ToUserId    = MM.UserId;
                        MR.IsAccept    = false;
                        MR.IsReject    = true;
                        MR.IsRequested = false;
                        db.MessageRequests.Add(MR);
                        db.SaveChanges();
                        if (MR.User_Master.DeviceToken != null)
                        {
                            if (MR.User_Master.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master.DeviceToken);
                            }
                        }
                        else if (MR.User_Master1.DeviceToken != null)
                        {
                            if (MR.User_Master1.DeviceType == "Android")
                            {
                                Helpers.NotificationHelper.sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                            else
                            {
                                sendMsgCallAccept(0, MR.ToUserId.Value, MR.User_Master1.DeviceToken);
                            }
                        }
                    }
                }
                return(MR);
            }
        }
        public object AddUserToGroup(UserGroupViewModel gVM)
        {
            List <MessageModel> Messages = new List <MessageModel>();

            using (LystenEntities db = new LystenEntities())
            {
                UserGroupMapping UGM = new UserGroupMapping();


                if (gVM.IsAdded == "1")
                {
                    var obj = gVM.UsersId.Split(',');
                    foreach (var item in obj)
                    {
                        int id = Convert.ToInt32(item);
                        if (!db.UserGroupMappings.Any(x => x.UserId == id && x.GroupId == gVM.GroupId))
                        {
                            UGM = new UserGroupMapping()
                            {
                                GroupId = gVM.GroupId,
                                UserId  = Convert.ToInt16(item)
                            };
                            db.UserGroupMappings.Add(UGM);
                            db.SaveChanges();

                            var group      = db.Groups.Where(x => x.Id == gVM.GroupId).FirstOrDefault();
                            var userdetail = db.User_Master.Where(x => x.Id == UGM.UserId).FirstOrDefault();


                            if (group.GroupTypeId == 2)
                            {
                                if (userdetail.DeviceToken != null && userdetail.DeviceToken != "")
                                {
                                    if (userdetail.DeviceType == "Android")
                                    {
                                        Helpers.NotificationHelper.sendMsgGroup(userdetail.Id, userdetail.DeviceToken, group.User_Master.FullName, group.Name, group.Id);
                                    }
                                    else
                                    {
                                        sendMsgGroup(userdetail.Id, userdetail.DeviceToken, group.User_Master.FullName, group.Name);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (gVM.IsAdded == "0")
                {
                    var obj = gVM.UsersId.Split(',');
                    foreach (var item in obj)
                    {
                        int id = Convert.ToInt32(item);
                        if (db.UserGroupMappings.Any(x => x.UserId == id && x.GroupId == gVM.GroupId))
                        {
                            UGM = db.UserGroupMappings.Where(x => x.UserId == id && x.GroupId == gVM.GroupId).FirstOrDefault();
                            if (UGM != null)
                            {
                                db.Entry(UGM).State = EntityState.Deleted;
                                db.SaveChanges();
                            }
                        }
                    }
                }
                else if (gVM.IsAdded == "2")
                {
                    var obj = gVM.UsersId.Split(',');
                    foreach (var item in obj)
                    {
                        int id = Convert.ToInt32(item);
                        if (db.UserGroupMappings.Any(x => x.UserId == id && x.GroupId == gVM.GroupId))
                        {
                            UGM = db.UserGroupMappings.Where(x => x.UserId == id && x.GroupId == gVM.GroupId).FirstOrDefault();
                            if (UGM != null)
                            {
                                db.Entry(UGM).State = EntityState.Deleted;
                                db.SaveChanges();
                            }
                        }
                    }

                    foreach (var item in obj)
                    {
                        int id = Convert.ToInt32(item);

                        var newgroupdata = db.UserGroupMappings.Where(x => x.GroupId == gVM.GroupId).Select(x => x.Id).ToList();


                        var msgRdata = db.MessageRecipients.Where(x => x.RecipientGroupId == gVM.GroupId).ToList();
                        if (msgRdata.Count > 0)
                        {
                            foreach (var itemss in msgRdata)
                            {
                                var msgdata = db.Messages.Where(x => x.Id == itemss.MessageId).FirstOrDefault();
                                if (msgdata != null)
                                {
                                    db.Entry(msgdata).State = EntityState.Deleted;
                                    db.SaveChanges();
                                }
                                var Mdata = db.MessageRecipients.Where(x => x.Id == itemss.Id).FirstOrDefault();
                                if (Mdata != null)
                                {
                                    db.Entry(Mdata).State = EntityState.Deleted;
                                    db.SaveChanges();
                                }
                            }
                        }

                        foreach (var itemss in newgroupdata)
                        {
                            UGM = db.UserGroupMappings.Where(x => x.Id == itemss).FirstOrDefault();
                            if (UGM != null)
                            {
                                db.Entry(UGM).State = EntityState.Deleted;
                                db.SaveChanges();
                            }
                        }
                        if (db.WebSocketSessionDbs.Any(x => x.GroupID == gVM.GroupId))
                        {
                            var websocket = db.WebSocketSessionDbs.Where(x => x.GroupID == gVM.GroupId).FirstOrDefault();
                            db.Entry(websocket).State = EntityState.Deleted;
                            db.SaveChanges();
                        }

                        if (db.Groups.Any(x => x.Id == gVM.GroupId && x.CreatorId == id))
                        {
                            var objdata = db.Groups.Where(x => x.Id == gVM.GroupId && x.CreatorId == id).FirstOrDefault();
                            db.Entry(objdata).State = EntityState.Deleted;
                            db.SaveChanges();
                        }
                    }
                }
                return(UGM);
            }
        }
示例#14
0
        public override void OnOpen()
        {
            try
            {
                clients.Add(this);
                if (this.WebSocketContext.RequestUri.Query.Split(',')[1].Split(':').Contains("GroupId"))
                {
                    var GroupId = this.WebSocketContext.RequestUri.Query.Split(',')[1].Split(':')[1];
                    var UserId  = this.WebSocketContext.RequestUri.Query.Split(',')[0].Split(':')[1];
                    using (LystenEntities db = new LystenEntities())
                    {
                        int gid = Convert.ToInt32(GroupId);
                        int uid = Convert.ToInt32(UserId);

                        //var obj = db.Groups.Where(x => x.Id == gid).FirstOrDefault();
                        //if (obj.GroupTypeId == 1)
                        //{
                        //    if (!db.Groups.Any(x => x.CreatorId == uid && x.Id == gid))
                        //    {
                        //        if (!db.UserGroupMappings.Any(x => x.UserId == uid && x.GroupId == gid))
                        //        {
                        //            UserGroupMapping ugm = new UserGroupMapping()
                        //            {
                        //                GroupId = gid,
                        //                UserId = uid
                        //            };
                        //            db.UserGroupMappings.Add(ugm);
                        //            db.SaveChanges();
                        //        }
                        //    }
                        //}
                        WebSocketSessionDb webs = new WebSocketSessionDb();

                        if (db.WebSocketSessionDbs.Any(x => x.GroupID == gid && x.UserId == uid))
                        {
                            webs                 = db.WebSocketSessionDbs.Where(x => x.GroupID == gid && x.UserId == uid).FirstOrDefault();
                            webs.GroupID         = Convert.ToInt32(GroupId);
                            webs.UserId          = Convert.ToInt32(UserId);
                            webs.SessionId       = this.WebSocketContext.SecWebSocketKey;
                            db.Entry(webs).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            webs.GroupID   = Convert.ToInt32(GroupId);
                            webs.UserId    = Convert.ToInt32(UserId);
                            webs.SessionId = this.WebSocketContext.SecWebSocketKey;
                            db.WebSocketSessionDbs.Add(webs);
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    var ReceiptionId = this.WebSocketContext.RequestUri.Query.Split(',')[1].Split(':')[1];
                    var UserId       = this.WebSocketContext.RequestUri.Query.Split(',')[0].Split(':')[1];
                    using (LystenEntities db = new LystenEntities())
                    {
                        int rid = Convert.ToInt32(ReceiptionId);
                        int uid = Convert.ToInt32(UserId);


                        WebSocketSessionDb webs = new WebSocketSessionDb();

                        if (db.WebSocketSessionDbs.Any(x => x.RecipientId == rid && x.UserId == uid))
                        {
                            webs                 = db.WebSocketSessionDbs.Where(x => x.RecipientId == rid && x.UserId == uid).FirstOrDefault();
                            webs.RecipientId     = Convert.ToInt32(rid);
                            webs.UserId          = Convert.ToInt32(UserId);
                            webs.SessionId       = this.WebSocketContext.SecWebSocketKey;
                            db.Entry(webs).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            webs.RecipientId = Convert.ToInt32(rid);
                            webs.UserId      = Convert.ToInt32(UserId);
                            webs.SessionId   = this.WebSocketContext.SecWebSocketKey;
                            db.WebSocketSessionDbs.Add(webs);
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
            }
        }
示例#15
0
        public async Task <ResultClass> PostLoginAuthenticationAsync(UserMasterModel objtblusermaster)
        {
            try
            {
                using (LystenEntities db = new LystenEntities())
                {
                    string baseURL = HttpContext.Current.Request.Url.Authority;
                    baseURL += (WebConfigurationManager.AppSettings["userimagepath"]).Replace("~", "");

                    //db.Configuration.LazyLoadingEnabled = false;
                    var pwd = SecutiryServices.EncodePasswordToBase64(objtblusermaster.Password);

                    User_Master result = (from um23 in db.User_Master
                                          where um23.Email.ToUpper() == objtblusermaster.UserNameorEmail.ToUpper() && um23.Password == pwd
                                          select um23
                                          ).FirstOrDefault();
                    if (result == null)
                    {
                        result = (from um23 in db.User_Master
                                  where um23.UserName.ToUpper() == objtblusermaster.UserNameorEmail.ToUpper() && um23.Password == pwd
                                  select um23
                                  ).FirstOrDefault();
                    }
                    var model = new
                    {
                    };
                    if (result != null)
                    {
                        var id = result.Id;
                        if (result.IsActive == true)
                        {
                            objresult.Code = (int)HttpStatusCode.OK;
                            objresult.Msg  = ap.Success;
                            //var user = result;
                            objresult.Data = AutoMapper.Mapper.Map <UserViewLoginModel>(result);
                            User_Master obj = result;//db.User_Master.Where(x => x.Id == id).FirstOrDefault();
                            obj.SessionId       = null;
                            obj.IsLogin         = true;
                            obj.DeviceType      = objtblusermaster.DeviceType;
                            obj.DeviceToken     = objtblusermaster.DeviceToken;
                            obj.TimeZone        = objtblusermaster.TimeZone;
                            db.Entry(obj).State = EntityState.Modified;
                            db.SaveChanges();
                            objresult.Data.Image = US.GetFavouriteImage(baseURL, result.Id);
                        }
                        else
                        {
                            objresult.Code = (int)HttpStatusCode.Accepted;
                            objresult.Msg  = ap.LoginUserIsNotActive;
                            //var user = result;
                            objresult.Data = AutoMapper.Mapper.Map <UserViewLoginModel>(result);
                        }
                    }
                    else if (result == null)
                    {
                        objresult.Code        = (int)HttpStatusCode.NotFound;
                        objresult.Msg         = ap.LoginUserInvalid;
                        objresult.Data        = model;
                        objresult.AccessToken = "";
                    }
                    else
                    {
                        objresult.Code = (int)HttpStatusCode.Accepted;
                        objresult.Msg  = ap.LoginUserIsNotActive;
                        result.Image   = US.GetFavouriteImage(baseURL, result.Id);

                        objresult.Data = AutoMapper.Mapper.Map <UserViewLoginModel>(result);
                    }

                    if (objresult.Code == (int)HttpStatusCode.OK)
                    {
                        TokenDetails objToken = await generatToken((result.Email), (result.Password), (result.DeviceToken));

                        //User_Master obj1 = db.User_Master.Where(x => x.Id == result.Id).FirstOrDefault();
                        //obj1.DeviceType = objtblusermaster.DeviceType;
                        ////obj.DeviceToken = objtblusermaster.DeviceToken;
                        //db.Entry(obj1).State = EntityState.Modified;
                        //db.SaveChanges();
                        (objresult.AccessToken) = objToken.access_token;
                        var obj = objresult.Data as UserViewLoginModel;
                        Add_UpdateToken(obj.Id, objToken, 1, objtblusermaster.DeviceType);
                    }
                    //if (updatetoken)
                    //{
                    //    (objresult.Data as UserViewModel).AccessToken = accessToken;
                    //}
                    //else
                    //{
                    //    (objresult.Data as UserViewModel).AccessToken = "";
                    //}
                    //db.Configuration.LazyLoadingEnabled = true;
                    return(objresult);
                }
            }
            catch (Exception ex)
            {
                objresult.Code        = (int)HttpStatusCode.NotAcceptable;
                objresult.Msg         = Convert.ToString(ex.Message);
                objresult.Data        = "";
                objresult.AccessToken = "";
                return(objresult);
            }
        }