//[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 { var sms = ctx.Sms.OrderByDescending(i => i.createdate).FirstOrDefault(i => i.userId == applicant.Id); TimeSpan span = DateTime.Now.Subtract(Convert.ToDateTime(sms.createdate)); if (span.TotalSeconds < 120) { throw new BusinessException("برای ارسال مجدد پیام لطفا 2 دقیقه منتظر بمانید"); } Sms smsUser = new Sms(); smsUser.userId = applicant.Id; smsUser.sms = char.Parse(smsCode.ToString()); smsUser.createdate = DateTime.Now; ctx.Sms.Add(smsUser); ctx.SaveChanges(); SendSms.SendSimpleSms2(user.Mobile, "کد تایید ورود شما در پایه باش : " + smsCode); } } } catch (Exception e) { if (e.InnerException != null) { res = e.InnerException.Message; } else { res = e.Message; } responseType = HttpStatusCode.InternalServerError; if (res == "برای ارسال مجدد پیام لطفا 2 دقیقه منتظر بمانید") { responseType = HttpStatusCode.ExpectationFailed; } if (res == "شما قبل عضو شده اید، وارد شوید") { responseType = HttpStatusCode.Forbidden; } if (res == "لطفا ابتدا عضو شوید") { responseType = System.Net.HttpStatusCode.BadRequest; } } return(new HttpResponseMessage(responseType) { Content = new StringContent(res, Encoding.UTF8) }); } else { return(null); } }
//[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); } }