public HttpResponseMessage Post(Trust trust) { PayeDBEntities db = new PayeDBEntities(); if (trust.VoteReciverUserId != null) { //var res = new BaseSystemModel.ApiResponse { Type = 0 }; var VoteReciverUserId = db.Users.FirstOrDefault(r => r.UserId.ToString() == trust.VoteReciverUserId).Id.ToString(); var item = db.Users.FirstOrDefault(i => i.UserId.ToString() == (null == trust.VoteReciverUserId ? trust.VoterUserId : trust.VoteReciverUserId)); try { item.TrustedVoteCount = db.TrustVotes.Where(j => j.VoteReciverUserId.ToString() == VoteReciverUserId && j.State == true).Count().ToString(); } catch (Exception e) { item.TrustedVoteCount = "0"; } TimeSpan t = (TimeSpan)(DateTime.Now - item.CreateDate); item.UserAge = ((int)t.TotalDays).ToString(); item.ActivityState = db.Posts.Where(i => i.userId.ToString() == VoteReciverUserId).Count().ToString() + "," + db.Posts.Where(i => i.applicants.Contains("," + item.Id + ",")).Count().ToString(); var VoterUserId = db.Users.Where(r => r.UserId.ToString() == trust.VoterUserId).FirstOrDefault().Id.ToString(); //VoteReciverUserId = db.Users.Where(r => r.UserId.ToString() == trust.VoteReciverUserId).FirstOrDefault().Id.ToString(); try { item.IsTrust = (bool)db.TrustVotes.FirstOrDefault(j => j.VoteReciverUserId.ToString() == VoteReciverUserId && j.VoterUserId.ToString() == VoterUserId).State; } catch (Exception e) { item.IsTrust = false; } return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json") }); } else { var item = db.Users.FirstOrDefault(i => i.UserId.ToString() == (null == trust.VoterUserId ? trust.VoterUserId : trust.VoterUserId)); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json") }); } }
public void SendToRoom(string roomName, string message) { try { using (var db = new PayeDBEntities()) { var user = db.Users.Where(u => u.Mobile /*UserName*/ == IdentityName).FirstOrDefault(); var room = db.Rooms.Where(r => r.Name == roomName).FirstOrDefault(); // Create and save message in database Message msg = new Message() { Content = Regex.Replace(message, @"(?i)<(?!img|a|/a|/img).*?>", String.Empty), Timestamp = DateTime.Now.Ticks.ToString(), FromUser = user, ToRoom = room }; db.Messages.Add(msg); db.SaveChanges(); // Broadcast the message var messageViewModel = Mapper.Map <Message, MessageViewModel>(msg); Clients.Group(roomName).newMessage(messageViewModel); } } catch (Exception) { Clients.Caller.onError("Message not send!"); } }
public HttpResponseMessage Get(string id) { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { PayeDBEntities db = new PayeDBEntities(); var result = (from x in db.Comments join c in db.Users on x.userId equals c.Id where x.postId.ToString() == id && x.state == true select new { Comment1 = x.comment, UserName = x.userName, Image = c.ProfileImage }).ToList(); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json") }); } else { return(null); } //CreateDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), ////CreateDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.CreateDate.ToString())).ToString().Substring(2, 14), }
public void DeleteRoom(string roomName) { try { using (var db = new PayeDBEntities()) { // Delete from database var room = db.Rooms.Where(r => r.Name == roomName && r.UserAccount.Mobile /*UserName*/ == IdentityName).FirstOrDefault(); db.Rooms.Remove(room); db.SaveChanges(); // Delete from list var roomViewModel = _Rooms.First <RoomViewModel>(r => r.Name == roomName); _Rooms.Remove(roomViewModel); // Move users back to Lobby Clients.Group(roomName).onRoomDeleted(string.Format("Room {0} has been deleted.\nYou are now moved to the Lobby!", roomName)); // Tell all users to update their room list Clients.All.removeChatRoom(roomViewModel); } } catch (Exception) { Clients.Caller.onError("Can't delete this chat room."); } }
public override Task OnConnected() { using (var db = new PayeDBEntities()) { try { var user = db.Users.Where(u => u.Mobile /*UserName*/ == IdentityName).FirstOrDefault(); var userViewModel = Mapper.Map <Paye.Models.User /*ApplicationUser*/, UserViewModel>(user); userViewModel.Device = GetDevice(); userViewModel.CurrentRoom = ""; _Connections.Add(userViewModel); _ConnectionsMap.Add(IdentityName, Context.ConnectionId); Clients.Caller.getProfileInfo(user.Name, user.ProfileImage); } catch (Exception ex) { Clients.Caller.onError("OnConnected:" + ex.Message); } } return(base.OnConnected()); }
public HttpResponseMessage Get(string id) { var httpRequest = HttpContext.Current.Request; PayeDBEntities db = new PayeDBEntities(); var list = db.Users.FirstOrDefault(x => x.UserId.ToString() == id); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(list.ServicesIds), Encoding.UTF8, "application/json") }); }
public IEnumerable <MessageViewModel> GetMessageHistory(string roomName) { using (var db = new PayeDBEntities()) { var messageHistory = db.Messages.Where(m => m.ToRoom.Name == roomName) .OrderByDescending(m => m.Timestamp) .Take(20) .AsEnumerable() .Reverse() .ToList(); return(Mapper.Map <IEnumerable <Message>, IEnumerable <MessageViewModel> >(messageHistory)); } }
//[SanatyarWebCms.CustomExceptionFilter] public HttpResponseMessage Post() { var res = ""; try { var httpRequest = HttpContext.Current.Request; var userId = httpRequest.Form.Get("UserId").Trim(); var postedFile = httpRequest.Files[0]; var image = Image.FromStream(postedFile.InputStream); var dir = HttpContext.Current.Server.MapPath("~/Images/Users/"); Random rnd = new Random(); var imageName = DateTime.Now.Ticks + rnd.Next(10000, 99999); string imagesName = ""; var bmp2 = ResizeImageByMinRatio(image, 200, 200); bmp2.Save(dir + imageName + ".jpg", ImageFormat.Jpeg); imagesName += imageName; PayeDBEntities db = new PayeDBEntities(); var list = db.Users.FirstOrDefault(x => x.UserId.ToString() == userId); list.ProfileImage = imagesName; db.SaveChanges(); return(new HttpResponseMessage() { Content = new StringContent(imageName.ToString()) }); } catch (Exception e) { if (e.InnerException != null) { res = e.InnerException.Message; } else { res = e.Message; } return(new HttpResponseMessage() { Content = new StringContent(res.ToString()) }); } }
//[SanatyarWebCms.CustomExceptionFilter] public HttpResponseMessage Post() { var httpRequest = HttpContext.Current.Request; var UserId = httpRequest.Form.Get("UserId").Trim(); var Message = httpRequest.Form.Get("Message").Trim(); if (string.IsNullOrEmpty(UserId) || string.IsNullOrEmpty(Message)) { throw new BusinessException("خطا در پارامترهای ورودی"); } var responseType = HttpStatusCode.OK; var res = ""; try { PayeDBEntities db = new PayeDBEntities(); if (Message != null) { FeedbackSuggestion tb = new FeedbackSuggestion(); tb.UserId = db.Users.FirstOrDefault(r => r.UserId.ToString() == UserId).Id.ToString(); tb.Message = Message; tb.CreateDate = DateTime.Now; tb.Status = false; db.FeedbackSuggestions.Add(tb); db.SaveChanges(); res = "با موفقیت ثبت شد"; } } catch (Exception e) { res = e.Message; responseType = System.Net.HttpStatusCode.InternalServerError; if (res == "خطا در اطلاعات ورودی!") { responseType = System.Net.HttpStatusCode.Forbidden; } } return(new HttpResponseMessage(responseType) { Content = new StringContent(res, Encoding.UTF8) }); }
public HttpResponseMessage Get(string id) { string PostCode = ""; if (null != id) { PostCode = id; } PayeDBEntities db = new PayeDBEntities(); var post = db.Posts.FirstOrDefault(x => x.postId.ToString() == PostCode); /*var result = from x in post * select new Posts * { * FullName = db.Users.Where(r => r.Id == x.UserId).FirstOrDefault().Name.Trim() + " " + db.Users.Where(r => r.Id == x.UserId).FirstOrDefault().Family.Trim(), * UserImage = db.Users.Where(r => r.Id == x.UserId).FirstOrDefault().ProfileImage, * Title = PersianNumber(x.Title), * Description = PersianNumber(x.Description), * Subject = x.Subject.Trim(), * City = x.City.Trim(), * ContactWays = x.ContactWays.Trim(), * Cost = PersianNumber(x.Cost).Trim(), * NumberFollowers = PersianNumber(x.NumberFollowers), * Images = Url.Content("~/Images/Paye/") + x.Images.Split(',')[0] + ".jpg", * CreateDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), * //CreateDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.CreateDate.ToString())).ToString().Substring(2, 14), * StartDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.StartDate.ToString())).ToString().Substring(2, 14), * finishDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.FinishDate.ToString())).ToString().Substring(2, 14), * //Deadline = Utilty.ToPersianDateTime(Convert.ToDateTime(x.Deadline.ToString())).ToString().Substring(2, 14), * Deadline = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(x.Deadline.ToString()), 0), * Tag = x.Tag.Trim(), * Longitude = x.Longitude, * Latitude = x.Latitude, * * };*/ post.PersianStartDate = post.startDate.ToString(); post.PersianFinishDate = post.endDate.ToString(); post.PersianDeadline = Utilty.ToPersianDateTime(Convert.ToDateTime(post.timeToJoin.ToString())).ToString().Substring(2, 14); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(post), Encoding.UTF8, "application/json") }); }
public void CreateRoom(string roomName) { try { using (var db = new PayeDBEntities()) { // Accept: Letters, numbers and one space between words. Match match = Regex.Match(roomName, @"^\w+( \w+)*$"); if (!match.Success) { Clients.Caller.onError("Invalid room name!\nRoom name must contain only letters and numbers."); } else if (roomName.Length < 5 || roomName.Length > 20) { Clients.Caller.onError("Room name must be between 5-20 characters!"); } else if (db.Rooms.Any(r => r.Name == roomName)) { Clients.Caller.onError("Another chat room with this name exists"); } else { // Create and save chat room in database var user = db.Users.Where(u => u.Mobile /*UserName*/ == IdentityName).FirstOrDefault(); var room = new Room() { Name = roomName, UserAccount = user }; db.Rooms.Add(room); db.SaveChanges(); if (room != null) { // Update room list var roomViewModel = Mapper.Map <Room, RoomViewModel>(room); _Rooms.Add(roomViewModel); Clients.All.addChatRoom(roomViewModel); } } }//using } catch (Exception ex) { Clients.Caller.onError("Couldn't create chat room: " + ex.Message); } }
public IEnumerable <RoomViewModel> GetRooms() { using (var db = new PayeDBEntities()) { // First run? if (_Rooms.Count == 0) { foreach (var room in db.Rooms) { var roomViewModel = Mapper.Map <Room, RoomViewModel>(room); _Rooms.Add(roomViewModel); } } } return(_Rooms.ToList()); }
public HttpResponseMessage Get() { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { PayeDBEntities db = new PayeDBEntities(); var list = (from x in db.Services orderby x.Id descending select x).ToList(); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(list), Encoding.UTF8, "application/json") }); } return(null); }
//[SanatyarWebCms.CustomExceptionFilter] public HttpResponseMessage Post(ParamsWrapper paramsWrapper) { var httpRequest = HttpContext.Current.Request; var ServicesIds = httpRequest.Form.Get("ServicesIds").Trim(); var userid = httpRequest.Form.Get("UserId").Trim(); var token = httpRequest.Form.Get("Token").Trim(); PayeDBEntities db = new PayeDBEntities(); var list = db.Users.FirstOrDefault(x => x.UserId.ToString() == userid); if (!string.IsNullOrEmpty(token)) { list.Token = token; } list.ServicesIds = ServicesIds.Trim(); db.SaveChanges(); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(list.ServicesIds), Encoding.UTF8, "application/json") }); }
//[ResponseType(typeof(Activity))] public HttpResponseMessage Post([FromBody] FormDataCollection formDataCollection) { var userId = formDataCollection.Get("UserId").Trim(); var token = formDataCollection.Get("RefreshToken").Trim(); PayeDBEntities db = new PayeDBEntities(); var list = (from x in db.Users where x.UserId == Guid.Parse(userId) select x).First(); list.Token = token; db.SaveChanges(); //Business.Expert.ExpertPersonBiz.Instance.UpdateRefreshToken(userid, token); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject("عملیات با موفقیت انجام شد"), Encoding.UTF8, "application/json") }); }
//[ResponseType(typeof(Activity))] public HttpResponseMessage Post() { PayeDBEntities db = new PayeDBEntities(); var httpRequest = HttpContext.Current.Request; var UserId = httpRequest.Form.Get("UserId"); var Name = httpRequest.Form.Get("Name"); var Family = httpRequest.Form.Get("Family"); var Telegram = httpRequest.Form.Get("Telegram"); var Instagram = httpRequest.Form.Get("Instagram"); var Soroosh = httpRequest.Form.Get("Soroosh"); var Gmail = httpRequest.Form.Get("Gmail"); var IsShowMobile = httpRequest.Form.Get("IsShowMobile"); var Age = httpRequest.Form.Get("Age"); var City = httpRequest.Form.Get("City"); var AboutMe = httpRequest.Form.Get("AboutMe"); var Favorites = httpRequest.Form.Get("Favorites"); var list = db.Users.FirstOrDefault(x => x.UserId.ToString() == UserId); list.Name = !string.IsNullOrEmpty(Name) ? Name : list.Name; list.Family = !string.IsNullOrEmpty(Family) ? Family : list.Family; list.City = !string.IsNullOrEmpty(City) ? City : list.City; list.Age = !string.IsNullOrEmpty(Age) ? Age : list.Age; list.Favorites = !string.IsNullOrEmpty(Favorites) ? Favorites : (string.IsNullOrEmpty(list.Favorites) ? "" : list.Favorites); list.AboutMe = !string.IsNullOrEmpty(AboutMe) ? AboutMe : (string.IsNullOrEmpty(list.AboutMe) ? "" : list.AboutMe); list.Telegram = !string.IsNullOrEmpty(Telegram) ? Telegram : (string.IsNullOrEmpty(list.Telegram) ? "" : list.Telegram); list.Gmail = !string.IsNullOrEmpty(Gmail) ? Gmail : (string.IsNullOrEmpty(list.Gmail) ? "" : list.Gmail); list.Instagram = !string.IsNullOrEmpty(Instagram) ? Instagram : (string.IsNullOrEmpty(list.Instagram) ? "" : list.Instagram); list.IsShowMobile = Convert.ToBoolean(IsShowMobile); list.Soroosh = !string.IsNullOrEmpty(Soroosh) ? Soroosh : (string.IsNullOrEmpty(list.Soroosh) ? "" : list.Soroosh); list.ModifiedDate = DateTime.Now; db.SaveChanges(); //Business.Expert.ExpertPersonBiz.Instance.UpdateRefreshToken(userid, token); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject("عملیات با موفقیت انجام شد"), Encoding.UTF8, "application/json") }); }
public HttpResponseMessage Post(ParamsWrapper formData) { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { int skip = (formData.Skip * 20) + 20; Guid UserId = formData.UserId; int cityCode = formData.city; int SubjectCode = formData.subject; string ids = formData.ids; string[] item = { "" }; var parentCodesplit = !string.IsNullOrEmpty(ids) ? ids.Split(',').ToArray() : item; var parentCodeList = parentCodesplit == null ? new List <string>() : parentCodesplit.ToList(); PayeDBEntities db = new PayeDBEntities(); //my posts var user = db.Users.FirstOrDefault(r => r.UserId == UserId); var query = (from x in db.Posts where x.userId == user.Id && (x.state == Models.Post.State_New || x.state == Models.Post.State_Ok || x.state == Models.Post.State_OkEdit) && (parentCodeList.Count == 0 || parentCodeList.Any(prefix => x.postId.ToString() == prefix)) && x.timeToJoin >= DateTime.Now orderby x.Id descending select new { PostId = x.postId.ToString().Trim(), Title = x.title.Trim(), City = x.city, IsWoman = x.isWoman, IsImmediate = x.isImmediate, Subject = x.subject, Cost = x.cost.Trim(), Images = null != x.images.Trim() ? (x.images) : "null", Tag = x.tag.Trim(), CreateDate = x.createDate.ToString(), timeToJoin = x.timeToJoin.ToString(), State = x.state }).Skip(skip - 20).Take(20).ToList(); var result = from x in query select new postsWrapper { postId = x.PostId.ToString().Trim(), title = x.Title.Trim(), city = x.City, subject = x.Subject, isWoman = (bool)x.IsWoman, isImmediate = (bool)x.IsImmediate, cost = x.Cost.Trim(), images = null != x.Images.Trim() ? (x.Images) : "null", tag = x.Tag.Trim(), createDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), timeToJoin = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(x.timeToJoin.ToString()), 0), state = ((bool)user.IsMobileAuthenticate) ? Dictioanry.GetStatesPayePost[(byte)x.State].ToString() + "-" + Dictioanry.GetStatesDescriptionPayePost[(byte)x.State].ToString() + "-" + Dictioanry.GetStatesColorPayePost[(byte)x.State].ToString() : "منتظر تایید شماره-لطفا شماره موبایل خود را تایید کنید.-#595FB1" }; return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json") }); } else { return(null); } //CreateDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), ////CreateDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.CreateDate.ToString())).ToString().Substring(2, 14), }
// 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); }
//[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); } }
public ActionResult Upload() { if (Request.Files.Count > 0) { try { var file = Request.Files[0]; // Some basic checks... if (file != null && !FileValidator.ValidSize(file.ContentLength)) { return(Json("File size too big. Maximum File Size: 500KB")); } else if (FileValidator.ValidType(file.ContentType)) { return(Json("This file extension is not allowed!")); } else { // Save file to Disk var fileName = DateTime.Now.ToString("yyyymmddMMss") + "_" + Path.GetFileName(file.FileName); var filePath = Path.Combine(Server.MapPath("~/Content/uploads/"), fileName); file.SaveAs(filePath); string htmlImage = string.Format( "<a href=\"/Content/uploads/{0}\" target=\"_blank\">" + "<img src=\"/Content/uploads/{0}\" class=\"post-image\">" + "</a>", fileName); using (var db = new PayeDBEntities()) { // Get sender & chat room var senderViewModel = ChatHub._Connections.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); var sender = db.Users.Where(u => u.Mobile /*UserName*/ == senderViewModel.Username).FirstOrDefault(); var room = db.Rooms.Where(r => r.Name == senderViewModel.CurrentRoom).FirstOrDefault(); // Build message Message msg = new Message() { Content = Regex.Replace(htmlImage, @"(?i)<(?!img|a|/a|/img).*?>", String.Empty), Timestamp = DateTime.Now.Ticks.ToString(), FromUser = sender, ToRoom = room }; db.Messages.Add(msg); db.SaveChanges(); // Send image-message to group var messageViewModel = Mapper.Map <Message, MessageViewModel>(msg); var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.Group(senderViewModel.CurrentRoom).newMessage(messageViewModel); } return(Json("Success")); } } catch (Exception ex) { return(Json("Error while uploading" + ex.Message)); } } return(Json("No files selected")); } // Upload
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") }); } }
//[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) { 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); } }
//[SanatyarWebCms.CustomExceptionFilter] public HttpResponseMessage Post() { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { var postid = httpRequest.Form.Get("postId"); var userid = httpRequest.Form.Get("userId"); int subject = Convert.ToInt32(httpRequest.Form.Get("subject")); var title = httpRequest.Form.Get("title"); var description = httpRequest.Form.Get("description"); int city = Convert.ToInt32(httpRequest.Form.Get("city")); var isWoman = httpRequest.Form.Get("isWoman"); var isImmediate = httpRequest.Form.Get("isImmediate"); var phoneNumber = httpRequest.Form.Get("phoneNumber"); var link = httpRequest.Form.Get("link"); var cost = httpRequest.Form.Get("cost"); var numberFollowers = httpRequest.Form.Get("numberFollowers"); var startDate = httpRequest.Form.Get("startDate"); var endDate = httpRequest.Form.Get("endDate"); var deadline = httpRequest.Form.Get("timeToJoin"); var tag = httpRequest.Form.Get("tag"); var longitude = httpRequest.Form.Get("longitude"); var latitude = httpRequest.Form.Get("latitude"); var isCommercial = httpRequest.Form.Get("isCommercial"); string imagesName = httpRequest.Form.Get("images"); foreach (string postedFile in httpRequest.Files) { var file = httpRequest.Files[postedFile]; if (file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName) && file.ContentType.Contains("image")) { var image = Image.FromStream(file.InputStream); var dir = HttpContext.Current.Server.MapPath("~/Images/PayeBash/"); var dirThumbnail = HttpContext.Current.Server.MapPath("~/Images/PayeBash/Thumbnail/"); Random rnd = new Random(); var imageName = DateTime.Now.Ticks; var bmp = ResizeImageByMinRatio(image, 150, 150); bmp.Save(dirThumbnail + imageName + ".jpg", ImageFormat.Jpeg); var bmp2 = ResizeImageByMinRatio(image, 512, 512); bmp2.Save(dir + imageName + ".jpg", ImageFormat.Jpeg); imagesName += imageName + ","; } } PayeDBEntities db = new PayeDBEntities(); if (postid == null) { Post tb = new Post(); var user = db.Users.Where(r => r.UserId.ToString() == userid).ToList().FirstOrDefault(); tb.userId = user.Id; tb.title = title.Trim(); tb.description = description == null ? "" : description.Trim(); tb.subject = subject; tb.city = city; tb.isWoman = Convert.ToBoolean(isWoman); tb.isImmediate = Convert.ToBoolean(isImmediate); tb.phoneNumber = phoneNumber == null ? "" : phoneNumber.Trim(); tb.link = link == null ? "" : link.Trim(); tb.cost = cost == null ? "" : cost.Trim(); tb.numberFollowers = numberFollowers == null ? "" : numberFollowers.Trim(); tb.images = imagesName == null ? "" : imagesName.Trim(); tb.createDate = DateTime.Now; tb.applicants = ""; tb.createDate = DateTime.Now; tb.startDate = startDate; tb.endDate = endDate; tb.timeToJoin = Convert.ToDateTime(deadline); tb.tag = tag == null ? "" : tag.Trim(); tb.longitude = longitude == null ? "" : longitude.Trim(); tb.latitude = latitude == null ? "" : latitude.Trim(); /*if (!(bool)user.IsMobileAuthenticate) * { * tb.State = 22; * } * * else*/ if (isCommercial == "true") { tb.service = Models.Post.State_Pay_Category; } if (isImmediate == "true") { tb.service = Models.Post.State_Pay_Immadiate; } tb.state = Models.Post.State_New; db.Posts.Add(tb); db.SaveChanges(); } else { var list = db.Posts.FirstOrDefault(x => x.postId.ToString() == postid); list.state = Models.Post.State_Edit; list.title = title.Trim(); list.description = description == null ? "" : description.Trim(); //list.Subject = subject.Trim(); list.city = city; list.isWoman = Convert.ToBoolean(isWoman); if (list.isImmediate != true) { list.isImmediate = Convert.ToBoolean(isImmediate); } list.phoneNumber = phoneNumber == null ? "" : phoneNumber.Trim(); list.link = link == null ? "" : link.Trim(); list.cost = cost == null ? "" : cost; list.numberFollowers = numberFollowers == null ? "" : numberFollowers.Trim(); list.images = imagesName == null ? "" : imagesName.Trim(); //list.Applicants = list.Applicants; list.startDate = startDate; list.endDate = endDate; list.timeToJoin = Convert.ToDateTime(deadline); list.tag = tag == null ? "" : tag.Trim(); list.longitude = longitude == null ? "" : longitude.Trim(); list.latitude = latitude == null ? "" : latitude.Trim(); list.modifiedDate = DateTime.Now; db.SaveChanges(); } //System.Collections.Generic.List<returnPost> map = new System.Collections.Generic.List<returnPost>(); returnPost item = new returnPost(); var a = db.Posts .OrderByDescending(p => p.Id) .FirstOrDefault(); item.postId = a.postId.ToString(); try { if ("" == a.images.ToString().Split(',')[0]) { item.postImage = "null"; } else { item.postImage = Url.Content("~/Images/Paye/") + a.images.ToString().Split(',')[0]; } } catch (Exception e) { string s = e.Message; item.postImage = "null"; } //map.Add(item); return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json") }); } else { return(null); } }
public HttpResponseMessage Post([FromBody] FormDataCollection formDataCollection) { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { int skip = (Convert.ToInt32(formDataCollection.Get("Skip")) * 20) + 20; Guid UserId = Guid.Empty; if (null != formDataCollection.Get("UserId")) { UserId = Guid.Parse(formDataCollection.Get("UserId").Trim()); } PayeDBEntities db = new PayeDBEntities(); { var userId = db.Users.FirstOrDefault(r => r.UserId == UserId).Id; var query = (from x in db.Posts where x.applicants.Contains("," + userId.ToString() + ",") && (x.state != 5 && x.state != 9) && x.timeToJoin >= DateTime.Now orderby x.Id descending select new { PostId = x.postId.ToString().Trim(), Title = x.title.Trim(), City = x.city, IsWoman = x.isWoman, IsImmediate = x.isImmediate, Subject = x.subject, Cost = x.cost.Trim(), Images = null != x.images.Trim() ? (x.images) : "null", Tag = x.tag.Trim(), CreateDate = x.createDate.ToString(), Deadline = x.timeToJoin.ToString(), State = x.state }).Skip(skip - 20).Take(20).ToList(); var result = from x in query select new postsWrapper { postId = x.PostId.ToString().Trim(), title = x.Title.Trim(), city = x.City, subject = x.Subject, isWoman = (bool)x.IsWoman, isImmediate = (bool)x.IsImmediate, cost = x.Cost.Trim(), images = null != x.Images.Trim() ? (x.Images) : "null", tag = x.Tag.Trim(), createDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), timeToJoin = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(x.Deadline.ToString()), 0), state = Dictioanry.GetStatesPayePost[(byte)x.State].ToString() + "-" + Dictioanry.GetStatesDescriptionPayePost[(byte)x.State].ToString() + "-" + Dictioanry.GetStatesColorPayePost[(byte)x.State].ToString() }; return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json") }); } } else { return(null); } //CreateDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), ////CreateDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.CreateDate.ToString())).ToString().Substring(2, 14), }
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") }); } }
public HttpResponseMessage Post(ParamsWrapper formData) { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { int skip = (formData.Skip * 20) + 20; Guid UserId = formData.UserId; int cityCode = formData.city; string contentSearch = formData.contentSearch.Trim(); int SubjectCode = formData.subject; string ids = formData.ids; string[] item = { "" }; var parentCodesplit = !string.IsNullOrEmpty(ids) ? ids.Split(',').ToArray() : item; var parentCodeList = parentCodesplit == item ? new List <string>() : parentCodesplit.ToList(); PayeDBEntities db = new PayeDBEntities(); //search if (cityCode != 0 || SubjectCode != 0 || !string.IsNullOrEmpty(contentSearch)) { var query = (from x in db.Posts where x.state == Models.Post.State_Ok && x.timeToJoin >= DateTime.Now && (cityCode == 0 || x.city == cityCode) && (SubjectCode == 0 || x.subject == SubjectCode) && (parentCodeList.Count == 0 || parentCodeList.Any(prefix => x.postId.ToString() == prefix)) && (string.IsNullOrEmpty(contentSearch) || x.title.Contains(contentSearch) || x.description.Contains(contentSearch) || x.tag.Contains(contentSearch)) orderby x.Id descending select new { postId = x.postId.ToString().Trim(), title = x.title.Trim(), city = x.city, subject = x.subject, cost = x.cost.Trim(), isWoman = x.isWoman, isImmediate = x.isImmediate, images = null != x.images.Trim() ? (x.images) : "null", tag = x.tag.Trim(), createDate = x.createDate.ToString(), timeToJoin = x.timeToJoin.ToString(), state = x.state }).Skip(skip - 20).Take(20).ToList(); var result = from x in query select new postsWrapper { postId = x.postId.ToString().Trim(), title = x.title.Trim(), city = x.city, subject = x.subject, cost = x.cost.Trim(), images = null != x.images.Trim() ? (x.images) : "null", tag = x.tag.Trim(), createDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.createDate.ToString()), DateTime.Now, 0), timeToJoin = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(x.timeToJoin.ToString()), 0), state = Dictioanry.GetStatesPayePost[(byte)x.state].ToString() + "-" + Dictioanry.GetStatesDescriptionPayePost[(byte)x.state].ToString() + "-" + Dictioanry.GetStatesColorPayePost[(byte)x.state].ToString() }; return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json") }); } else if (Guid.Empty == UserId) { var query = (from x in db.Posts where x.state == Models.Post.State_Ok && x.timeToJoin >= DateTime.Now && (parentCodeList.Count == 0 || parentCodeList.Any(prefix => x.postId.ToString() == prefix)) orderby x.Id descending select new { postId = x.postId.ToString().Trim(), title = x.title.Trim(), city = x.city, subject = x.subject, cost = x.cost.Trim(), isWoman = x.isWoman, isImmediate = x.isImmediate, images = null != x.images.Trim() ? (x.images) : "null", tag = x.tag.Trim(), createDate = x.createDate.ToString(), timeToJoin = x.timeToJoin.ToString(), state = x.state }).Skip(skip - 20).Take(20).ToList(); try { var result = from x in query select new postsWrapper { postId = x.postId.ToString().Trim(), title = x.title.Trim(), city = x.city, subject = x.subject, isWoman = (bool)x.isWoman, isImmediate = (bool)x.isImmediate, cost = x.cost.Trim(), images = null != x.images.Trim() ? (x.images) : "null", tag = x.tag.Trim(), createDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.createDate.ToString()), DateTime.Now, 0), timeToJoin = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(x.timeToJoin.ToString()), 0), state = Dictioanry.GetStatesPayePost[(byte)x.state].ToString() + "-" + Dictioanry.GetStatesDescriptionPayePost[(byte)x.state].ToString() + "-" + Dictioanry.GetStatesColorPayePost[(byte)x.state].ToString() }; return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json") }); } catch (Exception e) { return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(e.InnerException.Message), Encoding.UTF8, "application/json") }); } } else { return(null); } } else { return(null); } //CreateDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), ////CreateDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.CreateDate.ToString())).ToString().Substring(2, 14), }
public HttpResponseMessage Post(ParamsWrapper paramsWrapper) { var httpRequest = HttpContext.Current.Request; if (httpRequest.Headers["PayeBash"] != null) { var postid = paramsWrapper.PostId; var userid = paramsWrapper.UserId; PayeDBEntities db = new PayeDBEntities(); var userOwner = db.Users.FirstOrDefault(a => a.UserId == userid); Post post = null; if (userOwner != null) { post = db.Posts.FirstOrDefault(x => x.postId == postid && x.timeToJoin >= DateTime.Now); } else { post = db.Posts.FirstOrDefault(x => x.postId == postid && (x.state == Models.Post.State_Ok || x.state == Models.Post.State_OkEdit) && x.timeToJoin >= DateTime.Now); } /*var result = from x in post * select new Posts * { * FullName = db.Users.Where(r => r.Id == x.UserId).FirstOrDefault().Name.Trim() + " " + db.Users.Where(r => r.Id == x.UserId).FirstOrDefault().Family.Trim(), * UserImage = db.Users.Where(r => r.Id == x.UserId).FirstOrDefault().ProfileImage, * Title = PersianNumber(x.Title), * Description = PersianNumber(x.Description), * Subject = x.Subject.Trim(), * City = x.City.Trim(), * ContactWays = x.ContactWays.Trim(), * Cost = PersianNumber(x.Cost).Trim(), * NumberFollowers = PersianNumber(x.NumberFollowers), * Images = Url.Content("~/Images/Paye/") + x.Images.Split(',')[0] + ".jpg", * CreateDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(x.CreateDate.ToString()), DateTime.Now, 0), * //CreateDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.CreateDate.ToString())).ToString().Substring(2, 14), * StartDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.StartDate.ToString())).ToString().Substring(2, 14), * finishDate = Utilty.ToPersianDateTime(Convert.ToDateTime(x.FinishDate.ToString())).ToString().Substring(2, 14), * //Deadline = Utilty.ToPersianDateTime(Convert.ToDateTime(x.Deadline.ToString())).ToString().Substring(2, 14), * Deadline = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(x.Deadline.ToString()), 0), * Tag = x.Tag.Trim(), * Longitude = x.Longitude, * Latitude = x.Latitude, * * };*/ List <string> BaseProperty = new List <string>(); if (!string.IsNullOrEmpty(post.phoneNumber)) { BaseProperty.Add("شماره تماس : " + PersianNumber(post.phoneNumber).Trim()); } if (!string.IsNullOrEmpty(post.link)) { BaseProperty.Add("وب سایت : " + PersianNumber(post.link).Trim()); } BaseProperty.Add("هزینه : " + PersianNumber(post.cost).Trim()); BaseProperty.Add("تعداد هم پایه : " + PersianNumber(post.numberFollowers)); BaseProperty.Add("تاریخ شروع : " + post.startDate.ToString()); BaseProperty.Add("تاریخ پایان : " + post.endDate.ToString()); BaseProperty.Add("مهلت هم پا شدن : " + BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription2(DateTime.Now, Convert.ToDateTime(post.timeToJoin.ToString()), 0)); if (!string.IsNullOrEmpty(post.tag.Trim())) { BaseProperty.Add("هشتگ : " + post.tag.Trim()); } //BaseProperty.Add("راه های ارتباطی : " + post.ContactWays.Trim()); BaseProperty.Add("توضیحات : " + PersianNumber(post.description)); returnPostdetails post2 = new returnPostdetails(); var item = db.Users.Where(r => r.Id == post.userId).FirstOrDefault(); if (post.state == 9) { post2.title = post.title.Trim() + "(این برنامه لغو گردید)"; } else { post2.title = post.title.Trim(); } string[] Ids = post.applicants.Split(','); var query = (from x in db.Users where Ids.Any(a => a == x.Id.ToString()) orderby x.Id descending select new { UserId = x.UserId.ToString().Trim(), Name = x.Name.Trim(), Family = x.Family.Trim(), ProfileImage = x.ProfileImage.Trim(), IsMobileAuthenticate = x.IsMobileAuthenticate, }).ToList(); List <Applicant> result = (from x in query select new Applicant { UserId = x.UserId, ProfileImage = x.ProfileImage }).ToList(); List <string> applicants = new List <string>(); for (int i = 0; i < result.Count(); i++) { applicants.Add(result[i].UserId + "/" + result[i].ProfileImage); } post2.applicants = applicants; post2.isWoman = (bool)post.isWoman; post2.userId = item.UserId.ToString().Trim(); post2.telegram = item.Telegram.ToString().Trim(); post2.instagram = item.Instagram.ToString().Trim(); post2.soroosh = item.Soroosh.ToString().Trim(); post2.gmail = item.Gmail.ToString().Trim(); post2.city = post.city; post2.images = null != post.images.Trim() ? (post.images) : "null"; post2.createDate = BaseSystemModel.ResizeImage.GetDateDifferencesAsDescription(Convert.ToDateTime(post.createDate.ToString()), DateTime.Now, 0); post2.subject = post.subject; post2.latitude = post.latitude.Trim(); post2.longitude = post.longitude.Trim(); if ((bool)item.IsMobileAuthenticate) { post2.state = Dictioanry.GetStatesPayePost[(byte)post.state].ToString() + "-" + Dictioanry.GetStatesDescriptionPayePost[(byte)post.state].ToString() + "-" + Dictioanry.GetStatesColorPayePost[(byte)post.state].ToString(); } else { post2.state = "منتظر تایید شماره-لطفا شماره موبایل خود را تایید کنید.-#595FB1"; } var user = db.Users.Where(r => r.Id == post.userId).FirstOrDefault(); post2.username = user.Name.Trim() + " " + user.Family.Trim(); post2.token = user.Token.Trim(); if (user.IsShowMobile != null && (bool)user.IsShowMobile) { post2.mobile = user.Mobile.Trim(); } else { post2.mobile = ""; } post2.profileimage = !user.ProfileImage.Contains("https://") ? Url.Content("~/Images/Users/") + user.ProfileImage + ".jpg" : user.ProfileImage; post2.baseProperty = BaseProperty; List <CommentModel> comments = (from x in db.Comments where x.postId == postid && x.state == true select new CommentModel { userName = x.userName, comment = x.comment }).ToList(); List <string> Comments = new List <string>(); for (int i = 0; i < comments.Count(); i++) { Comments.Add(comments[i].userName + " : " + comments[i].comment); } post2.comments = Comments; return(new HttpResponseMessage() { Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(post2), Encoding.UTF8, "application/json") }); } else { return(null); } }