コード例 #1
0
        //[SanatyarWebCms.CustomExceptionFilter]
        public HttpResponseMessage Post([FromBody] FormDataCollection formDataCollection)
        {
            string s      = formDataCollection.Get("UserId").ToString().Trim();
            string token  = formDataCollection.Get("FbToken").ToString().Trim();
            var    record = db.Users.FirstOrDefault(i => i.UserId.ToString() == s);

            record.Token = token;
            db.SaveChanges();
            returnUser item = new returnUser();

            item.FullName       = record.Name.ToString() + " " + record.Family.ToString();
            item.IsAuthenticate = record.IsAuthenticate.ToString();
            item.ProfileImage   = record.ProfileImage;
            item.ServicesIds    = record.ServicesIds;
            item.Instagram      = record.Instagram;
            item.Telegram       = record.Telegram;
            item.Soroosh        = record.Soroosh;
            if ((bool)record.IsMobileAuthenticate)
            {
                item.Mobile     = record.Mobile;
                item.MobileTemp = record.Mobile;
            }

            else
            {
                item.Mobile     = "";
                item.MobileTemp = record.Mobile;
            }
            return(new HttpResponseMessage()
            {
                Content =
                    new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(item), Encoding.UTF8)
            });
        }
コード例 #2
0
        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.");
            }
        }
コード例 #3
0
        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!");
            }
        }
コード例 #4
0
        //[SanatyarWebCms.CustomExceptionFilter]
        public HttpResponseMessage Post()
        {
            var httpRequest = HttpContext.Current.Request;
            var UserId      = httpRequest.Form.Get("UserId").Trim();
            var Comment     = httpRequest.Form.Get("Comment").Trim();
            var PostId      = httpRequest.Form.Get("PostId").Trim();
            var UserName    = httpRequest.Form.Get("UserName").Trim();

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

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

            try
            {
                Comment tb = new Comment();
                tb.userId     = db.Users.FirstOrDefault(r => r.UserId.ToString() == UserId).Id;
                tb.postId     = Guid.Parse(PostId);
                tb.userName   = UserName;
                tb.comment    = Comment;
                tb.createDate = DateTime.Now;
                tb.state      = true;
                db.Comments.Add(tb);
                db.SaveChanges();
                //res = "با موفقیت ثبت شد";
                return(new HttpResponseMessage(responseType)
                {
                    Content =
                        new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(tb), Encoding.UTF8)
                });
            }
            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)
            });
        }
コード例 #5
0
        //[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)
            });
        }
コード例 #6
0
        //[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())
                });
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        //[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")
            });
        }
コード例 #9
0
        //[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")
            });
        }
コード例 #10
0
        //[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")
            });
        }
コード例 #11
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")
                });
            }
        }
コード例 #12
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);
        }
コード例 #13
0
        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
コード例 #14
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
                        {
                            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);
            }
        }
コード例 #15
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")
                });
            }
        }
コード例 #16
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);
        }
コード例 #17
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);
            }
        }
コード例 #18
0
        //[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);
            }
        }
コード例 #19
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);
            }
        }