public IActionResult addPermissionName([FromBody] PermissionObj form)
        {
            try
            {
                var userId = this.help.GetCurrentUser(HttpContext);
                if (userId <= 0)
                {
                    return(StatusCode(401, "الرجاء الـتأكد من أنك قمت بتسجيل الدخول"));
                }
                var perm = this.help.getPermissin("Permissions_Add", userId, db);
                if (!perm)
                {
                    return(StatusCode(401, "لا تملك الصلاحية"));
                }


                if (form == null)
                {
                    return(BadRequest("حذث خطأ في ارسال البيانات الرجاء إعادة الادخال"));
                }



                var Years = (from p in db.Permissions where p.Name == form.name select p).SingleOrDefault();

                if (Years != null)
                {
                    return(StatusCode(401, "الاسم موجود مسبقا"));
                }

                Permissions pre = new Permissions();
                pre.Name      = form.name;
                pre.State     = 1;
                pre.CreatedBy = userId;
                pre.CreatedOn = DateTime.Now;
                db.Permissions.Add(pre);
                db.SaveChanges();

                return(Ok("تمت عملية الاضافة بنجاح"));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public IActionResult SentMessage([FromBody] MessageContent Message)
        {
            try
            {
                if (Message == null)
                {
                    return(BadRequest("حذث خطأ في ارسال البيانات الرجاء إعادة الادخال"));
                }

                var userId = this.help.GetCurrentUser(HttpContext);
                if (userId <= 0)
                {
                    return(BadRequest("لا يمكنك الوصول لهذه الصفحة , الرجاء تسجيل الدخول"));
                }

                Messages MS = new Messages();
                MS.CreatedBy = userId;
                MS.CreatedOn = DateTime.Now;
                MS.Payload   = Message.Payload;
                MS.Subject   = Message.Subject;

                db.Messages.Add(MS);

                MessageTransaction MT = new MessageTransaction();
                MT.SentByStudent    = userId;
                MT.RecivedByStudent = Message.RecivedByStudent;
                MT.MessageId        = MS.MesssageId;
                MT.CreatedBy        = userId;
                MT.CreatedOn        = DateTime.Now;
                MT.IsRead           = 1;

                db.MessageTransaction.Add(MT);
                db.SaveChanges();

                return(Ok("لقد قمت بإرسال الرسالة بنـجاح"));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public async Task <IActionResult> loginUser([FromBody] user loginUser)
        {
            try
            {
                if (loginUser == null)
                {
                    return(NotFound("الرجاء ادخال البريد الالكتروني او اسم الدخول"));
                }

                //if (!Validation.IsValidEmail(loginUser.Email))
                //{
                //    return BadRequest("Please enter correct email address");
                //}
                if (string.IsNullOrWhiteSpace(loginUser.Email))
                {
                    return(BadRequest("الرجاء ادخال البريد الالكتروني او اسم الدخول"));
                }

                if (string.IsNullOrWhiteSpace(loginUser.Password))
                {
                    return(BadRequest("الرجاء ادخال كلمه المرور"));
                }

                var cUser = (from p in db.Users
                             where (p.Email == loginUser.Email || p.LoginName == loginUser.Email) && p.Status != 9
                             select p).SingleOrDefault();

                if (cUser == null)
                {
                    return(NotFound("الرجاء التاكد من البريد الالكتروني وكلمة المرور"));
                }

                if (cUser.UserType != 1 && cUser.UserType != 2 && cUser.UserType != 3)
                {
                    return(BadRequest("ليس لديك صلاحيه للدخول علي النظام"));
                }

                if (cUser.Status == 0)
                {
                    return(BadRequest("حسابك غير مفعل"));
                }

                if (!Security.VerifyHash(loginUser.Password, cUser.Password, HashAlgorithms.SHA512))
                {
                    //cUser.LoginTryAttempts++;
                    //if (cUser.LoginTryAttempts >= 5 && cUser.Status == 1)
                    //{
                    //    cUser.LoginTryAttemptDate = DateTime.Now;
                    //    cUser.Status = 2;
                    //}
                    //db.SaveChanges();
                    return(NotFound("الرجاء التاكد من البريد الالكتروني وكلمة المرور"));
                }

                //string hospital = "";
                //if (cUser.UserType == 5 && cUser.HospitalId != null && cUser.HospitalId > 0)
                //{
                //    hospital = db.Hospital.Where(x => x.HospitalId == cUser.HospitalId).SingleOrDefault().Name;
                //}

                db.SaveChanges();
                //long branchId = -1;
                // int branchType = -1;
                var pre = (from p in db.Permissions
                           join g in db.PermissionGroup on p.Id equals g.PermissioinId
                           where (g.GroupId == cUser.GroupId)
                           select p.Name).ToList();
                string preCsv   = string.Join(",", pre.ToArray());
                var    userInfo = new
                {
                    userId   = cUser.Id,
                    fullName = cUser.Name,
                    userType = cUser.UserType,
                    //branchId = branchId,
                    LoginName  = cUser.LoginName,
                    Email      = cUser.Email,
                    Gender     = cUser.Gender,
                    Status     = cUser.Status,
                    Phone      = cUser.Phone,
                    Photo      = cUser.Image,
                    BirthDate  = cUser.BirthDate,
                    Permission = preCsv
                };

                const string Issuer = "http://www.nid.ly";
                var          claims = new List <Claim>();
                claims.Add(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/id", cUser.Id.ToString(), ClaimValueTypes.Integer64, Issuer));
                claims.Add(new Claim(ClaimTypes.Name, cUser.Name, ClaimValueTypes.String, Issuer));
                claims.Add(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/OfficeId", ClaimValueTypes.Integer64, Issuer));
                claims.Add(new Claim("userType", cUser.UserType.ToString(), ClaimValueTypes.Integer32, Issuer));
                var userIdentity = new ClaimsIdentity("thisisasecreteforauth");
                userIdentity.AddClaims(claims);
                var userPrincipal = new ClaimsPrincipal(userIdentity);

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    userPrincipal,
                    new AuthenticationProperties
                {
                    ExpiresUtc   = DateTime.UtcNow.AddHours(1),
                    IsPersistent = true,
                    AllowRefresh = true
                });

                return(Ok(userInfo));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public IActionResult AddUser([FromBody] UsersObject user)
        {
            try
            {
                var userId = this.help.GetCurrentUser(HttpContext);
                if (userId <= 0)
                {
                    return(StatusCode(401, "الرجاء الـتأكد من أنك قمت بتسجيل الدخول"));
                }
                var perm = this.help.getPermissin("Users_Add", userId, db);
                if (!perm)
                {
                    return(StatusCode(401, "لا تملك الصلاحية"));
                }
                if (user == null)
                {
                    return(BadRequest("خطأ في إرسال البيانات"));
                }


                if (string.IsNullOrWhiteSpace(user.LoginName))
                {
                    return(BadRequest("الرجاء ادحال اسم المسنخدم بطريقة صحيحة"));
                }

                if (string.IsNullOrWhiteSpace(user.FullName))
                {
                    return(BadRequest("الرجاء إدخال الاسم الرباعي"));
                }

                if (!Validation.IsValidEmail(user.Email))
                {
                    return(BadRequest("الرجاء ادخال الايميل بالطريقة الصحيحة"));
                }

                if (user.Gender != 1 && user.Gender != 2)
                {
                    return(BadRequest("الرجاء ادخال الجنس (ذكر - انثي)"));
                }
                if (string.IsNullOrWhiteSpace(user.DateOfBirth.ToString()))
                {
                    return(BadRequest("الرجاء دخال تاريخ الميلاد المستخدم"));
                }
                //if ((DateTime.Now.Year - user.DateOfBirth.Year) < 18)
                //{
                //    return BadRequest("يجب ان يكون عمر المستخدم اكبر من 18");
                //}

                var cLoginName = (from u in db.Users
                                  where u.LoginName == user.LoginName
                                  select u).SingleOrDefault();
                if (cLoginName != null)
                {
                    return(BadRequest(" اسم الدخول موجود مسبقا"));
                }


                var cPhone = (from u in db.Users
                              where u.Phone == user.Phone
                              select u).SingleOrDefault();
                if (cPhone != null)
                {
                    return(BadRequest(" رقم الهاتف موجود مسبقا"));
                }

                var cUser = (from u in db.Users
                             where u.Email == user.Email && u.Status != 9
                             select u).SingleOrDefault();

                if (cUser != null)
                {
                    if (cUser.Status == 0)
                    {
                        return(BadRequest("هدا المستخدم موجود من قبل يحتاج الي تقعيل الحساب فقط"));
                    }
                    if (cUser.Status == 1 || cUser.Status == 2)
                    {
                        return(BadRequest("هدا المستخدم موجود من قبل يحتاج الي دخول فقط"));
                    }
                }

                cUser = new Users();


                cUser.Phone            = user.Phone;
                cUser.LoginName        = user.LoginName;
                cUser.Name             = user.FullName;
                cUser.Email            = user.Email;
                cUser.BirthDate        = user.DateOfBirth;
                cUser.CreatedBy        = userId;
                cUser.CreatedOn        = DateTime.Now;
                cUser.Gender           = (short)user.Gender;
                cUser.LoginTryAttempts = 0;
                cUser.UserType         = user.UserType;
                cUser.GroupId          = user.GroupId;
                cUser.Password         = Security.ComputeHash(user.Password, HashAlgorithms.SHA512, null);
                if (user.Photo == null)
                {
                    cUser.Image = Convert.
                                  FromBase64String("/9j/4QZJRXhpZgAATU0AKgAAAAgABwESA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AAAAAALY3JvcFJlY3RUb3Bsb25nAAAAAAA4QklNA+0AAAAAABAASAAAAAEAAQBIAAAAAQABOEJJTQQmAAAAAAAOAAAAAAAAAAAAAD+AAAA4QklNBA0AAAAAAAQAAABaOEJJTQQZAAAAAAAEAAAAHjhCSU0D8wAAAAAACQAAAAAAAAAAAQA4QklNJxAAAAAAAAoAAQAAAAAAAAABOEJJTQP1AAAAAABIAC9mZgABAGxmZgAGAAAAAAABAC9mZgABAKGZmgAGAAAAAAABADIAAAABAFoAAAAGAAAAAAABADUAAAABAC0AAAAGAAAAAAABOEJJTQP4AAAAAABwAAD/////////////////////////////A+gAAAAA/////////////////////////////wPoAAAAAP////////////////////////////8D6AAAAAD/////////////////////////////A+gAADhCSU0EAAAAAAAAAgAAOEJJTQQCAAAAAAACAAA4QklNBDAAAAAAAAEBADhCSU0ELQAAAAAABgABAAAAAjhCSU0ECAAAAAAAEAAAAAEAAAJAAAACQAAAAAA4QklNBB4AAAAAAAQAAAAAOEJJTQQaAAAAAANJAAAABgAAAAAAAAAAAAAAjAAAAIwAAAAKAFUAbgB0AGkAdABsAGUAZAAtADEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAIwAAACMAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAEAAAAAAABudWxsAAAAAgAAAAZib3VuZHNPYmpjAAAAAQAAAAAAAFJjdDEAAAAEAAAAAFRvcCBsb25nAAAAAAAAAABMZWZ0bG9uZwAAAAAAAAAAQnRvbWxvbmcAAACMAAAAAFJnaHRsb25nAAAAjAAAAAZzbGljZXNWbExzAAAAAU9iamMAAAABAAAAAAAFc2xpY2UAAAASAAAAB3NsaWNlSURsb25nAAAAAAAAAAdncm91cElEbG9uZwAAAAAAAAAGb3JpZ2luZW51bQAAAAxFU2xpY2VPcmlnaW4AAAANYXV0b0dlbmVyYXRlZAAAAABUeXBlZW51bQAAAApFU2xpY2VUeXBlAAAAAEltZyA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HJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjJhNDMzZTU1LTc5OWQtNDU0ZS1iNWU1LWFiMDYxZjk1MDU4YSIgc3RFdnQ6d2hlbj0iMjAxNy0xMi0wMVQxOTozNDoxNyswMjowMCIgc3RFdnQ6c29mdHdhcmVBZ2VudD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTUgKFdpbmRvd3MpIiBzdEV2dDpjaGFuZ2VkPSIvIi8+IDwvcmRmOlNlcT4gPC94bXBNTTpIaXN0b3J5PiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA8P3hwYWNrZXQgZW5kPSJ3Ij8+/+IMWElDQ19QUk9GSUxFAAEBAAAMSExpbm8CEAAAbW50clJHQiBYWVogB84AAgAJAAYAMQAAYWNzcE1TRlQAAAAASUVDIHNSR0IAAAAAAAAAAAAAAAEAAPbWAAEAAAAA0y1IUCAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARY3BydAAAAVAAAAAzZGVzYwAAAYQAAABsd3RwdAAAAfAAAAAUYmtwdAAAAgQAAAAUclhZWgAAAhgAAAAUZ1hZWgAAAiwAAAAUYlhZWgAAAkAAAAAUZG1uZAAAAlQAAABwZG1kZAAAAsQAAACIdnVlZAAAA0wAAACGdmlldwAAA9QAAAAkbHVtaQAAA/gAAAAUbWVhcwAABAwAAAAkdGVjaAAABDAAAAAMclRSQwAABDwAAAgMZ1RSQwAABDwAAAgMYlRSQwAABDwAAAgMdGV4dAAAAABDb3B5cmlnaHQgKGMpIDE5OTggSGV3bGV0dC1QYWNrYXJkIENvbXBhbnkAAGRlc2MAAAAAAAAAEnNSR0IgSUVDNjE5NjYtMi4xAAAAAAAAAAAAAAASc1JHQiBJRUM2MTk2Ni0yLjEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AgBAwABBQD5XTnT6U//2gAIAQEAAQUA+QeQEDDewBaq+wyOrPYSose6hlVFRU12NiyIMximJhX2ZorhFYUekj2jZJkPkHyoZatLpuHq2vzgvVkzTct612cJvdM0zB+SJnTD77DTaq5K/OtVyTtM1vdDzpm91hpVEVLCC+IbKmr3gTVdg8kLGDH/AKJWt7GvYUajLh68BOms5xAHIIhJGFHNjjHqkyRRhTJppRcqq26aDyo4EP7AxOS5p5T9EW6lBZHu4ZeNc1zfxKsokbkq8lF45znO2AlSAOi37V5/dD8X6T//2gAIAQICBj8AIn//2gAIAQMCBj8AIn//2gAIAQEBBj8A/MapXCDjt6hakUZfiTpHjbCJAONTbzwqRwJHfWwViYmP3Zc7VBqDkbyg80zehfE2MkrFmO09EKSXhPqTdxFlkjOpGFQbpnbBVBJ6hZ5XzY4DcNg6Z+Mx8r+ZOBGf0upaZmg5kXEDe9a9RNDdS8NJ/sLiAb5F77qZNpQ066YXEe5KsewfvdTFTQ0HKorcQ6TSrAGm7bdTrStUanXTC4jP2hieRF1Q5HO2k4xtUxnh0zPJTVIo0Dcpxxuy49UR1dmR6UcWwmrdQxN4yNirAgjgbPGc0Yqew06Ms5z9C958LwyStpUfU7haWQYB3ZgDnQmvRPx5DpdnLKTkagCley7MkhoBkNpO4W1uaKPQmwDpr8f5BwySQ9xuKyyBNwOfLOxEEZb3PgOQsGlOXpUYAXKowEiLgK11U67AOTE3uy5iwZSCpyIxH4kO+p/sXE/xYrF/yThi3OxZiSxzJxN7WJyu8bD2ZWC/JSnvTLtFv9f9l0b6+Gf6L//Z");
                }
                else
                {
                    cUser.Image = Convert.FromBase64String(user.Photo.Substring(user.Photo.IndexOf(",") + 1));
                }
                cUser.CreatedOn = DateTime.Now;

                //1- Active
                //2- locked
                //9- deleted not exist
                cUser.Status = 1;
                db.Users.Add(cUser);

                db.SaveChanges();
                return(Ok("تم تسجيل المستخدم بنجاح "));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public async Task <IActionResult> loginUser([FromBody] user loginUser)
        {
            try
            {
                if (loginUser == null)
                {
                    return(NotFound("الرجاء ادخال البريد الالكتروني او اسم الدخول"));
                }

                if (string.IsNullOrWhiteSpace(loginUser.Email))
                {
                    return(BadRequest("الرجاء ادخال البريد الالكتروني او اسم الدخول"));
                }

                if (string.IsNullOrWhiteSpace(loginUser.Password))
                {
                    return(BadRequest("الرجاء ادخال كلمه المرور"));
                }

                var cUser = (from p in db.Users
                             where (p.Email == loginUser.Email || p.LoginName == loginUser.Email) && p.State != 9
                             select p).SingleOrDefault();

                if (cUser == null)
                {
                    return(NotFound("الرجاء التاكد من البريد الالكتروني وكلمة المرور"));
                }


                if (cUser.State == 0)
                {
                    return(BadRequest("حسابك غير مفعل"));
                }
                if (cUser.State == 2)
                {
                    if (cUser.LoginTryAttemptDate != null)
                    {
                        DateTime dt     = cUser.LoginTryAttemptDate.Value;
                        double   minuts = 30;
                        dt = dt.AddMinutes(minuts);
                        if (dt >= DateTime.Now)
                        {
                            return(BadRequest("لايمكنك الدخول للنظام: تم ايقافك"));
                        }
                        else
                        {
                            cUser.State = 1;

                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        return(BadRequest("لايمكنك الدخول للنظام: تم ايقافك"));
                    }
                }

                if (!Security.VerifyHash(loginUser.Password, cUser.Password, HashAlgorithms.SHA512))
                {
                    cUser.LoginTryAttempts++;
                    if (cUser.LoginTryAttempts >= 5 && cUser.State == 1)
                    {
                        cUser.LoginTryAttemptDate = DateTime.Now;
                        cUser.State = 2;
                    }
                    db.SaveChanges();
                    return(NotFound("الرجاء التاكد من البريد الالكتروني وكلمة المرور"));
                }


                cUser.LoginTryAttempts = 0;
                cUser.LastLoginOn      = DateTime.Now;
                db.SaveChanges();

                var userInfo = new
                {
                    userId      = cUser.UserId,
                    fullName    = cUser.Name,
                    LoginName   = cUser.LoginName,
                    DateOfBirth = cUser.BirthDate,
                    Email       = cUser.Email,
                    Gender      = cUser.Gender,
                    State       = cUser.State,
                    Phone       = cUser.Phone,
                    UserType    = cUser.UserType,
                    SecretKey   = Guid.NewGuid()
                                  //OfficeState=cUser.Office.State
                };

                //const string Issuer = "http://www.nid.ly";
                const string Issuer = "http://localhost:4810";
                var          claims = new List <Claim>();
                claims.Add(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/id", cUser.UserId.ToString(), ClaimValueTypes.Integer64, Issuer));
                claims.Add(new Claim(ClaimTypes.Name, cUser.Name, ClaimValueTypes.String, Issuer));
                //  claims.Add(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/OfficeId", cUser.OfficeId.ToString(), ClaimValueTypes.Integer64, Issuer));
                //claims.Add(new Claim("userType", cUser.UserType.ToString(), ClaimValueTypes.Integer32, Issuer));
                var userIdentity = new ClaimsIdentity("thisisasecreteforauth");
                userIdentity.AddClaims(claims);
                var userPrincipal = new ClaimsPrincipal(userIdentity);

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    userPrincipal,
                    new AuthenticationProperties
                {
                    ExpiresUtc   = DateTime.UtcNow.AddHours(1),
                    IsPersistent = true,
                    AllowRefresh = true
                });

                return(Ok(userInfo));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }