コード例 #1
0
        public HttpResponseMessage Post(UserItem user)
        {
            PayeDBEntities db = new PayeDBEntities();

            //var res = new BaseSystemModel.ApiResponse { Type = 0 };
            try
            {
                returnUser r    = new returnUser();
                var        item = db.Users.FirstOrDefault(i => /*i.Name == GN && i.Family == FN &&*/ i.Gmail == user.Email);
                if (item != null)
                {
                    //item.IsAuthenticate = true;
                    item.Token           = user.Token;
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    r.UserId         = item.UserId.ToString();
                    r.FullName       = item.Name.ToString() + " " + item.Family.ToString();
                    r.ProfileImage   = item.ProfileImage;
                    r.ServicesIds    = item.ServicesIds;
                    r.IsAuthenticate = item.IsAuthenticate.ToString();
                    r.Message        = "ورود با موفقیت انجام شد";

                    return(new HttpResponseMessage()
                    {
                        Content =
                            new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(r), Encoding.UTF8, "application/json")
                    });
                }
                else
                {
                    User tb = new User();

                    tb.Name   = user.GivenName.Trim();
                    tb.Family = user.FamilyName.Trim();
                    if (string.IsNullOrEmpty(user.Mobile))
                    {
                        tb.Mobile = "";
                    }
                    else
                    {
                        tb.Mobile = user.Mobile;
                    }

                    if (string.IsNullOrEmpty(user.City))
                    {
                        tb.City = "";
                    }
                    else
                    {
                        tb.City = user.City;
                    }

                    //tb.SmsCode = smsCode.ToString();
                    tb.Token = string.IsNullOrEmpty(user.Token.Trim()) ? "" : user.Token.Trim();
                    if (string.IsNullOrEmpty(user.Age))
                    {
                        tb.Age = "";
                    }
                    else
                    {
                        tb.Age = user.Age;
                    }
                    tb.ServicesIds = "";
                    tb.Instagram   = "";
                    tb.Telegram    = "";
                    tb.Soroosh     = "";
                    tb.CreateDate  = DateTime.Now;
                    //tb.IsAuthenticate = false;
                    ////////////////////////////////
                    if (string.IsNullOrEmpty(user.Email))
                    {
                        tb.Gmail = "";
                    }
                    else
                    {
                        tb.Gmail = user.Email;
                    }
                    /////////////////////////////////
                    if (string.IsNullOrEmpty(user.Aboutme))
                    {
                        tb.AboutMe = "";
                    }
                    else
                    {
                        tb.AboutMe = user.Aboutme;
                    }
                    /////////////////////////////////
                    if (string.IsNullOrEmpty(user.Images))
                    {
                        tb.ProfileImage = "";
                    }
                    else
                    {
                        tb.ProfileImage = user.Images.Replace("lh4", "lh3").Replace("?sz=50", "");
                    }

                    db.Users.Add(tb);
                    db.SaveChanges();

                    var endUser = db.Users
                                  .OrderByDescending(p => p.Id).ToList()
                                  .FirstOrDefault();

                    r.UserId         = endUser.UserId.ToString();
                    r.FullName       = endUser.Name.ToString() + " " + endUser.Family.ToString();
                    r.ProfileImage   = endUser.ProfileImage;
                    r.ServicesIds    = endUser.ServicesIds;
                    r.IsAuthenticate = endUser.IsAuthenticate.ToString();
                    r.Message        = "ثبت نام با موفقیت انجام شد";

                    return(new HttpResponseMessage()
                    {
                        Content =
                            new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(r), Encoding.UTF8, "application/json")
                    });
                }
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(ex.Message), Encoding.UTF8, "application/json")
                });
            }
        }
コード例 #2
0
        public HttpResponseMessage Post([FromBody] FormDataCollection formDataCollection)
        {
            PayeDBEntities db = new PayeDBEntities();

            //var res = new BaseSystemModel.ApiResponse { Type = 0 };
            try
            {
                var mobile  = formDataCollection.Get("Mobile").Trim();
                var smsCode = formDataCollection.Get("SmsCode").Trim();
                var UserId  = formDataCollection.Get("UserId").Trim();
                if (string.IsNullOrEmpty(mobile))
                {
                    return(new HttpResponseMessage()
                    {
                        Content =
                            new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject("خطا در پارامترهای ورودی"), Encoding.UTF8, "application/json")
                    });
                }

                else
                {
                    returnUser r = new returnUser();
                    //var item = db.Users.FirstOrDefault(i => i.UserId.ToString() == UserId);
                    var item    = db.Users.FirstOrDefault(i => i.Mobile.ToString() == mobile);
                    var smsUser = db.Sms.FirstOrDefault(i => i.userId.ToString() == UserId);
                    if (item != null)
                    {
                        if (smsUser.sms.ToString() != smsCode.Trim())
                        {
                            r.UserId   = "0";
                            r.FullName = "";
                            r.Message  = "کد وارد شده اشتباه است";
                            return(new HttpResponseMessage()
                            {
                                Content =
                                    new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(r), Encoding.UTF8, "application/json")
                            });
                        }
                        else if (smsUser.sms.ToString().Trim() == smsCode.Trim())
                        {
                            /*var list = db.Posts.Where(x => x.UserId == item.Id).ToList();
                             * foreach (var room in list)
                             * {
                             *  //db.Posts.Attach(room);
                             *  if((bool)room.IsImmediate && room.State == 1)
                             *  {
                             *      room.State = 1;
                             *      db.SaveChanges();
                             *  }
                             *  else if (room.State == 22 && (bool)room.)
                             *  {
                             *      room.State = 2;
                             *      db.SaveChanges();
                             *  }
                             *
                             * }*/

                            item.IsAuthenticate       = true;
                            item.IsMobileAuthenticate = true;
                            db.Entry(item).State      = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            r.UserId       = item.UserId.ToString();
                            r.FullName     = item.Name.ToString() + " " + item.Family.ToString();
                            r.ProfileImage = item.ProfileImage;
                            r.ServicesIds  = item.ServicesIds;
                            r.Message      = "ورود با موفقیت انجام شد";

                            return(new HttpResponseMessage()
                            {
                                Content =
                                    new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(r), Encoding.UTF8, "application/json")
                            });
                        }
                    }

                    r.UserId   = "0";
                    r.FullName = "";
                    r.Message  = "این شماره موبایل در سیستم وجود ندارد";

                    return(new HttpResponseMessage()
                    {
                        Content =
                            new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(r), Encoding.UTF8, "application/json")
                    });
                }
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(ex.Message), Encoding.UTF8, "application/json")
                });
            }
        }
コード例 #3
0
        //[SanatyarWebCms.CustomExceptionFilter]
        public HttpResponseMessage Post(UserItem user)
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Headers["PayeBash"] != null)
            {
                if (string.IsNullOrEmpty(user.Email))
                {
                    if (string.IsNullOrEmpty(user.Mobile))
                    {
                        throw new BusinessException("خطا در پارامترهای ورودی");
                    }
                }

                var responseType = HttpStatusCode.OK;
                var res          = "";

                string id;
                var    r       = new Random();
                var    smsCode = r.Next(111111, 999999);
                try
                {
                    using (var ctx = new PayeDBEntities())
                    {
                        var applicant = ctx.Users.FirstOrDefault(i => (!string.IsNullOrEmpty(user.UserId) && i.UserId.ToString() == user.UserId));
                        if (applicant == null)
                        {
                            applicant = ctx.Users.FirstOrDefault(i => (!string.IsNullOrEmpty(user.Email) && i.Gmail == user.Email));
                        }
                        if (applicant == null)
                        {
                            applicant = ctx.Users.FirstOrDefault(i => (!string.IsNullOrEmpty(user.Mobile) && i.Mobile == user.Mobile));
                        }
                        if (applicant != null)
                        {
                            if (user.Type == "Register" && string.IsNullOrEmpty(user.Email))
                            {
                                throw new BusinessException("شما قبل عضو شده اید، وارد شوید");
                            }

                            else
                            {
                                var      date = applicant.ModifiedDate;
                                TimeSpan span = DateTime.Now.Subtract(Convert.ToDateTime(date));
                                if (span.TotalSeconds < 150 && user.Type != "Update" /* &&
                                                                                      * ((user.Type != "Update"&&string.IsNullOrEmpty(user.Email)) || (user.Type == "Update" && string.IsNullOrEmpty(applicant.Mobile)))*/)
                                {
                                    throw new BusinessException("برای ارسال مجدد پیام لطفا 2 دقیقه منتظر بمانید");
                                }

                                else
                                {
                                    //if ((user.Type != "Update" && string.IsNullOrEmpty(user.Email)) || (user.Type == "Update" && /*applicant.IsAuthenticate != true &&*/ applicant.IsMobileAuthenticate != true))
                                    if (user.Type != "Update")
                                    {
                                        SendSms.SendSimpleSms2(user.Mobile, "کد تایید ورود شما در پایه باش : " + smsCode);
                                    }

                                    if (!string.IsNullOrEmpty(user.Token))
                                    {
                                        applicant.Token = user.Token;
                                    }
                                    if (!string.IsNullOrEmpty(user.Name))
                                    {
                                        applicant.Name = user.Name;
                                    }
                                    if (!string.IsNullOrEmpty(user.Family))
                                    {
                                        applicant.Family = user.Family;
                                    }
                                    if (!string.IsNullOrEmpty(user.City))
                                    {
                                        applicant.City = user.City;
                                    }
                                    if (!string.IsNullOrEmpty(user.Age))
                                    {
                                        applicant.Age = user.Age;
                                    }
                                    if (!string.IsNullOrEmpty(user.Email))
                                    {
                                        applicant.Gmail = user.Email;
                                    }
                                    if (!string.IsNullOrEmpty(user.Mobile))
                                    {
                                        applicant.Mobile = user.Mobile;
                                    }
                                    //if (applicant.IsAuthenticate)
                                    //{
                                    applicant.ModifiedDate     = DateTime.Now;
                                    ctx.Entry(applicant).State = System.Data.Entity.EntityState.Modified;

                                    //applicant.IsAuthenticate = true;
                                    Sms smsUser = new Sms();
                                    smsUser.userId     = applicant.Id;
                                    smsUser.sms        = char.Parse(smsCode.ToString());
                                    smsUser.createdate = DateTime.Now;
                                    ctx.Sms.Add(smsUser);

                                    ctx.SaveChanges();
                                    //}
                                    id  = applicant.UserId.ToString();
                                    res = id;
                                }
                            }
                        }

                        else
                        {
                            if (user.Type == "Login" && user.Name == null && user.Family == null)
                            {
                                throw new BusinessException("لطفا ابتدا عضو شوید");
                            }
                            else if (user.Type == "Register" ||
                                     (user.Type == "Login" && user.Name != null && user.Family != null && user.Email != null && user.Images != null))
                            {
                                //var date = applicant.ModifiedDate;
                                //TimeSpan span = DateTime.Now.Subtract(Convert.ToDateTime(date));
                                //if (span.TotalSeconds < 120)
                                //    throw new BusinessException("برای ارسال مجدد پیام لطفا 2 دقیقه منتظر بمانید");
                                //else
                                {
                                    User tb = new User();

                                    tb.Name   = user.Name.Trim();
                                    tb.Family = user.Family.Trim();
                                    if (string.IsNullOrEmpty(user.Mobile))
                                    {
                                        tb.Mobile = "";
                                    }
                                    else
                                    {
                                        tb.Mobile = user.Mobile;
                                    }

                                    if (string.IsNullOrEmpty(user.City))
                                    {
                                        tb.City = "";
                                    }
                                    else
                                    {
                                        tb.City = user.City;
                                    }

                                    //tb.SmsCode = smsCode.ToString();
                                    Sms smsUser = new Sms();
                                    smsUser.userId     = applicant.Id;
                                    smsUser.sms        = char.Parse(smsCode.ToString());
                                    smsUser.createdate = DateTime.Now;
                                    ctx.Sms.Add(smsUser);



                                    tb.Token = string.IsNullOrEmpty(user.Token.Trim()) ? "" : user.Token.Trim();
                                    if (string.IsNullOrEmpty(user.Age))
                                    {
                                        tb.Age = "";
                                    }
                                    else
                                    {
                                        tb.Age = user.Age;
                                    }
                                    tb.IsMobileAuthenticate = false;
                                    tb.ServicesIds          = "";
                                    tb.Instagram            = "";
                                    tb.Telegram             = "";
                                    tb.Soroosh        = "";
                                    tb.CreateDate     = DateTime.Now;
                                    tb.IsAuthenticate = true;
                                    ////////////////////////////////
                                    if (string.IsNullOrEmpty(user.Email))
                                    {
                                        tb.Gmail = "";
                                    }
                                    else
                                    {
                                        tb.Gmail = user.Email;
                                    }
                                    /////////////////////////////////
                                    if (string.IsNullOrEmpty(user.Aboutme))
                                    {
                                        tb.AboutMe = "";
                                    }
                                    else
                                    {
                                        tb.AboutMe = user.Aboutme;
                                    }
                                    /////////////////////////////////
                                    if (string.IsNullOrEmpty(user.Images))
                                    {
                                        tb.ProfileImage = "";
                                    }
                                    else
                                    {
                                        tb.ProfileImage = user.Images.Replace("lh4", "lh3").Replace("?sz=50", "");
                                    }

                                    db.Users.Add(tb);
                                    db.SaveChanges();

                                    id = db.Users
                                         .OrderByDescending(p => p.Id).ToList()
                                         .FirstOrDefault().UserId.ToString();
                                    //if (user.Type != "Update" && string.IsNullOrEmpty(user.Email))
                                    //    SendSms.SendSimpleSms2(user.Mobile, "کد تایید ورود شما در پایه باش : " + smsCode);
                                    res = id;
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        res = e.InnerException.Message;
                    }
                    else
                    {
                        res = e.Message;
                    }
                    responseType = System.Net.HttpStatusCode.InternalServerError;

                    if (res == "برای ارسال مجدد پیام لطفا 2 دقیقه منتظر بمانید")
                    {
                        responseType = System.Net.HttpStatusCode.ExpectationFailed;
                    }
                    if (res == "شما قبل عضو شده اید، وارد شوید")
                    {
                        responseType = System.Net.HttpStatusCode.Forbidden;
                    }

                    if (res == "لطفا ابتدا عضو شوید")
                    {
                        responseType = System.Net.HttpStatusCode.BadRequest;
                    }
                }


                return(new HttpResponseMessage(responseType)
                {
                    Content =
                        new StringContent(res, Encoding.UTF8)
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        //[SanatyarWebCms.CustomExceptionFilter]
        public HttpResponseMessage Post(UserItem user)
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Headers["PayeBash"] != null)
            {
                if (string.IsNullOrEmpty(user.Email))
                {
                    if (string.IsNullOrEmpty(user.Mobile))
                    {
                        throw new BusinessException("خطا در پارامترهای ورودی");
                    }
                }

                var responseType = HttpStatusCode.OK;
                var res          = "";

                string id;
                var    r       = new Random();
                var    smsCode = r.Next(111111, 999999);
                try
                {
                    using (var ctx = new PayeDBEntities())
                    {
                        var applicant = ctx.Users.FirstOrDefault(i => (!string.IsNullOrEmpty(user.UserId) && i.UserId.ToString() == user.UserId));
                        if (applicant == null)
                        {
                            applicant = ctx.Users.FirstOrDefault(i => (!string.IsNullOrEmpty(user.Email) && i.Gmail == user.Email));
                        }
                        if (applicant == null)
                        {
                            applicant = ctx.Users.FirstOrDefault(i => (!string.IsNullOrEmpty(user.Mobile) && i.Mobile == user.Mobile));
                        }


                        if (applicant == null)
                        {
                            throw new BusinessException("لطفا ابتدا عضو شوید");
                        }

                        else
                        {
                            if (!string.IsNullOrEmpty(user.Token))
                            {
                                applicant.Token = user.Token;
                            }
                            if (!string.IsNullOrEmpty(user.Name))
                            {
                                applicant.Name = user.Name;
                            }
                            if (!string.IsNullOrEmpty(user.Family))
                            {
                                applicant.Family = user.Family;
                            }
                            if (!string.IsNullOrEmpty(user.City))
                            {
                                applicant.City = user.City;
                            }
                            if (!string.IsNullOrEmpty(user.Age))
                            {
                                applicant.Age = user.Age;
                            }
                            if (!string.IsNullOrEmpty(user.Email))
                            {
                                applicant.Gmail = user.Email;
                            }
                            if (!string.IsNullOrEmpty(user.Mobile))
                            {
                                applicant.Mobile = user.Mobile;
                            }
                            //if (applicant.IsAuthenticate)
                            //{
                            applicant.ModifiedDate     = DateTime.Now;
                            ctx.Entry(applicant).State = System.Data.Entity.EntityState.Modified;
                            ctx.SaveChanges();
                            //}
                            id  = applicant.UserId.ToString();
                            res = id;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        res = e.InnerException.Message;
                    }
                    else
                    {
                        res = e.Message;
                    }
                    responseType = System.Net.HttpStatusCode.InternalServerError;

                    if (res == "برای ارسال مجدد پیام لطفا 2 دقیقه منتظر بمانید")
                    {
                        responseType = System.Net.HttpStatusCode.ExpectationFailed;
                    }
                    if (res == "شما قبل عضو شده اید، وارد شوید")
                    {
                        responseType = System.Net.HttpStatusCode.Forbidden;
                    }

                    if (res == "لطفا ابتدا عضو شوید")
                    {
                        responseType = System.Net.HttpStatusCode.BadRequest;
                    }
                }


                return(new HttpResponseMessage(responseType)
                {
                    Content =
                        new StringContent(res, Encoding.UTF8)
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
        // POST: api/Report
        public string Post(ReportWrapper report)
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Headers["PayeBash"] != null)
            {
                PayeDBEntities db = new PayeDBEntities();
                if (report.ComplainantId != null &&
                    report.Type != null)
                {
                    var             complainantId = db.Users.FirstOrDefault(i => i.UserId.ToString() == report.ComplainantId).Id;
                    /*long*/ string userId        = "0";
                    long            postId        = 0;
                    int             cnt           = 0;
                    if (!string.IsNullOrEmpty(report.UserId))
                    {
                        userId = db.Users.FirstOrDefault(i => i.UserId.ToString() == report.UserId).Id;
                        cnt    = db.ReportPosts.Where(i => i.ComplainantId == complainantId && i.UserId == userId).Count();
                    }

                    else if (!string.IsNullOrEmpty(report.PostId))
                    {
                        postId = db.Posts.Where(r => r.postId.ToString() == report.PostId).FirstOrDefault().Id;
                        cnt    = db.ReportPosts.Where(i => i.ComplainantId == complainantId && i.PostId == postId).Count();
                    }


                    if (cnt > 0)
                    {
                        var record = db.ReportPosts.FirstOrDefault(i => i.ComplainantId == complainantId && (i.PostId == postId || i.UserId == userId));
                        record.Type            = report.Type;
                        record.Modifiedate     = DateTime.Now;
                        db.Entry(record).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        return("گزارش شما با موفقیت ثبت گردید");
                    }
                    else
                    {
                        try
                        {
                            ReportPost tb = new ReportPost();
                            tb.ComplainantId = complainantId;
                            tb.PostId        = postId;
                            tb.UserId        = userId;
                            tb.Type          = report.Type;
                            tb.Status        = false;
                            tb.Modifiedate   = DateTime.Now;
                            db.ReportPosts.Add(tb);
                            db.SaveChanges();

                            return("گزارش شما با موفقیت ثبت گردید");;
                        }
                        catch (Exception ex)
                        {
                            return("خطا در ارسال");
                        }
                    }
                }
                else
                {
                    return("خطا در ارسال");
                }
            }
            return(null);
        }
コード例 #6
0
        public HttpResponseMessage Post()
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Headers["PayeBash"] != null)
            {
                var VoterUserId       = httpRequest.Form.Get("VoterUserId");
                var VoteReciverUserId = httpRequest.Form.Get("VoteReciverUserId");

                if (string.IsNullOrEmpty(VoterUserId) || string.IsNullOrEmpty(VoteReciverUserId))
                {
                    throw new BusinessException("خطا در پارامترهای ورودی");
                }

                VoterUserId       = db.Users.Where(r => r.UserId.ToString() == VoterUserId).FirstOrDefault().Id.ToString().Trim();
                VoteReciverUserId = db.Users.FirstOrDefault(r => r.UserId.ToString() == VoteReciverUserId).Id.ToString().Trim();

                var res = false;

                try
                {
                    var record = db.TrustVotes.Where(i => i.VoterUserId.ToString() == VoterUserId && i.VoteReciverUserId.ToString() == VoteReciverUserId).FirstOrDefault();
                    if (record != null)
                    {
                        if (record.State == true)
                        {
                            record.State = false;
                            res          = false;
                        }
                        else if (record.State == false)
                        {
                            record.State = true;
                            res          = true;
                        }

                        record.ModeifidDate    = DateTime.Now;
                        db.Entry(record).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        TrustVote tb = new TrustVote();
                        tb.VoterUserId       = Convert.ToInt64(VoterUserId);
                        tb.VoteReciverUserId = Convert.ToInt64(VoteReciverUserId);
                        tb.State             = true;
                        tb.ModeifidDate      = DateTime.Now;

                        db.TrustVotes.Add(tb);
                        db.SaveChanges();
                        res = true;
                    }
                }
                catch (Exception e)
                {
                    return(new HttpResponseMessage()
                    {
                        Content =
                            new StringContent(e.Message, Encoding.UTF8)
                    });
                }
                return(new HttpResponseMessage()
                {
                    Content =
                        new StringContent(res.ToString(), Encoding.UTF8)
                });
            }
            return(null);
        }