Example #1
0
        public IHttpActionResult GetMadadkarInfo()
        {
            MadadkarModel model      = new MadadkarModel();
            var           identity   = (ClaimsIdentity)User.Identity;
            var           MadadkarId = identity.Claims.Where(s => s.Type == "MadadkarId").FirstOrDefault();
            int           MadadkarID = int.Parse(MadadkarId.Value);
            var           SIPResult  = SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == MadadkarID).FirstOrDefault();

            if (SIPResult == null)
            {
                var selectedExt = SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == null).FirstOrDefault();
                selectedExt.MadadkarId   = MadadkarID;
                selectedExt.MadadkarName = identity.Name;
                selectedExt.RegDate      = DateTime.Now;
                SipDataEntity.SaveChanges();
            }
            SIPResult = SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == MadadkarID).FirstOrDefault();

            return(Ok(new MadadkarModel {
                MadadkarName = identity.Name,
                MadadkarId = MadadkarID,
                SipDisplayname = SIPResult.DisplayName,
                SipExtention = SIPResult.Extention.ToString(),
                SipPassword = SIPResult.Password,
                SipUrl = string.Format("sip:{0}@vs.sharifngo.com", SIPResult.Extention),
                SipWsUrl = "ws://vs.sharifngo.com:8088/ws"
            }));
        }
        public IHttpActionResult GetMadadkarInfo()
        {
            MadadkarModel model      = new MadadkarModel();
            var           identity   = (ClaimsIdentity)User.Identity;
            var           MadadkarId = identity.Claims.Where(s => s.Type == "MadadkarId").FirstOrDefault();
            int           MadadkarID = int.Parse(MadadkarId.Value);
            var           SIPResult  = SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == MadadkarID).FirstOrDefault();

            if (SIPResult == null)
            {
                if (SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == null).Count() == 0)
                {
                    int max = int.Parse(SipDataEntity.SIPExtensions.OrderByDescending(x => x.Id).Select(x => x.DisplayName).FirstOrDefault());
                    max += 1;

                    var s = new SIPExtensions()
                    {
                        DisplayName  = max.ToString(),
                        Extention    = max,
                        MadadkarId   = MadadkarID,
                        MadadkarName = identity.Name,
                        RegDate      = DateTime.Now,
                        Password     = System.Web.Security.Membership.GeneratePassword(15, 5),
                        Enabled      = false
                    };
                    SipDataEntity.SIPExtensions.Add(s);
                    SipDataEntity.SaveChanges();
                }
                else
                {
                    var selectedExt = SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == null).FirstOrDefault();
                    selectedExt.MadadkarId   = MadadkarID;
                    selectedExt.MadadkarName = identity.Name;
                    selectedExt.RegDate      = DateTime.Now;
                    SipDataEntity.SaveChanges();
                }
            }
            SIPResult = SipDataEntity.SIPExtensions.Where(s => s.MadadkarId == MadadkarID).FirstOrDefault();

            return(Ok(new MadadkarModel {
                MadadkarName = identity.Name,
                MadadkarId = MadadkarID,
                SipDisplayname = SIPResult.DisplayName,
                SipExtention = SIPResult.Extention.ToString(),
                SipPassword = SIPResult.Password,
                SipUrl = string.Format("sip:{0}@vs.sharifngo.com", SIPResult.Extention),
                SipWsUrl = "ws://vs.sharifngo.com:8088/ws"
            }));
        }