Exemplo n.º 1
0
            private static ConfessLoader GetConfessLoader(Confess dt, string key)
            {
                ConfessLoader loader = new ConfessLoader
                {
                    Body         = dt.Body,
                    Category     = dt.Category,
                    Date         = Shared.TimeAgo.Ago(dt.Date),//$"{dt.Date.ToLongDateString()} {dt.Date.ToShortTimeString()}",
                    DateReal     = dt.Date,
                    DisLikes     = DislikeClass.GetCount(dt.Guid, false),
                    Likes        = LikeClass.GetCount(dt.Guid, false),
                    Guid         = dt.Guid,
                    Owner_Guid   = dt.Owner_Guid,
                    Title        = dt.Title,
                    CommentCount = CommentClass.GetCommentCount(dt.Guid),
                    Seen         = SeenClass.GetCount(dt.Guid)
                };

                //load colors
                if (LikeClass.CheckExistence(dt.Guid, false, key))
                {
                    loader.LikeColorString = "#1976D2";
                }

                if (DislikeClass.CheckExistence(dt.Guid, false, key))
                {
                    loader.DislikeColorString = "#1976D2";
                }

                return(loader);
            }
Exemplo n.º 2
0
        public static async void PushToEveryone(Confess confess)
        {
            string newbody = "";

            if (confess.Body.Length > 35)
            {
                newbody = $"{confess.Body.Substring(0, 30)}...";
            }
            else
            {
                newbody = confess.Body;
            }

            PushToAll dataToPush = new PushToAll()
            {
                notification_content = new NotificationContent()
                {
                    title       = "New Confession 📢!",
                    body        = confess.Body,
                    name        = Guid.NewGuid().ToString().Replace("-", ""),
                    custom_data = new Dictionary <string, string> {
                        { "key1", confess.Guid },
                        { "key2", confess.Owner_Guid },
                        { "type", "Confession" },
                        { "sender", confess.Owner_Guid }
                    }
                }
            };

            await PushToServer(dataToPush);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Update(Modeller confessed)
        {
            Confess confess = confessed.Confess;

            try
            {
                if (string.IsNullOrWhiteSpace(confess.Title) ||
                    string.IsNullOrWhiteSpace(confess.Body) ||
                    string.IsNullOrWhiteSpace(confess.Category))
                {
                    return(RedirectToActionPermanent($"Edit/{confess.Guid}", "Home"));
                }
                Confess fetch = await Store.ConfessClass.FetchOneConfessByGuid(confess.Guid, GetToken(GetKey()));

                fetch.Title    = confess.Title;
                fetch.Body     = confess.Body;
                fetch.Category = confess.Category;

                //Save
                await Store.ConfessClass.UpdateConfess(fetch, GetToken(GetKey()));

                return(RedirectToActionPermanent($"Edit/{confess.Guid}", "Home"));
            }
            catch (Exception)
            {
                return(RedirectToActionPermanent($"Edit/{confess.Guid}", "Home"));
            }
        }
Exemplo n.º 4
0
        private async void UpdateButton_Clicked(object sender, EventArgs e)
        {
            if (!Logic.IsInternet())
            {
                DependencyService.Get <IMessage>().ShortAlert(Constants.No_Internet);
                return;
            }
            if (string.IsNullOrEmpty(title.Text))
            {
                DependencyService.Get <IMessage>().ShortAlert("Please type a Title");
                return;
            }
            if (cat.SelectedItem == null)
            {
                DependencyService.Get <IMessage>().ShortAlert("Please choose a Category");
                return;
            }
            if (string.IsNullOrEmpty(body.Text))
            {
                DependencyService.Get <IMessage>().ShortAlert("Please type a Body");
                return;
            }
            if (title.Text.Length > 50)
            {
                DependencyService.Get <IMessage>().ShortAlert("The Title is rather too long");
                return;
            }
            if (body.Text.Length < 100)
            {
                DependencyService.Get <IMessage>().ShortAlert("Please type more texts for the Body");
                return;
            }


            ChangeLoading(true);
            await Task.Delay(10);

            try
            {
                Confess fetch = new Confess
                {
                    Guid     = confess.Guid,
                    Title    = title.Text,
                    Body     = body.Text,
                    Category = cat.SelectedItem.ToString()
                };
                //Update
                MessagingCenter.Send <object, Confess>(this, Constants.update_confession, fetch);

                //await Store.ConfessClass.UpdateConfess(fetch);
                ChangeLoading(false);

                //close this page
                await Navigation.PopModalAsync();
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex, Logic.GetErrorProperties(ex));
            }
        }
Exemplo n.º 5
0
        private async void CreateButton_Clicked(object sender, EventArgs e)
        {
            if (!Logic.IsInternet())
            {
                DependencyService.Get <IMessage>().ShortAlert(Constants.No_Internet);
                return;
            }
            if (string.IsNullOrWhiteSpace(title.Text.Trim()))
            {
                DependencyService.Get <IMessage>().ShortAlert("Please type a Title");
                return;
            }
            if (cat.SelectedItem == null)
            {
                DependencyService.Get <IMessage>().ShortAlert("Please choose a Category");
                return;
            }
            if (string.IsNullOrWhiteSpace(body.Text))
            {
                DependencyService.Get <IMessage>().ShortAlert("Please type a Body");
                return;
            }
            if (title.Text.Length > 50)
            {
                DependencyService.Get <IMessage>().ShortAlert("The Title is rather too long");
                return;
            }
            if (body.Text.Length < 100)
            {
                DependencyService.Get <IMessage>().ShortAlert("Please type more texts for the Body");
                return;
            }



            try
            {
                ChangeLoading(true);
                Confess confess = new Confess()
                {
                    Title      = title.Text.Trim(),
                    Body       = body.Text.Trim(),
                    Category   = cat.SelectedItem.ToString(),
                    Owner_Guid = await Logic.GetKey(),
                };
                //Send to Confession Model
                MessagingCenter.Send <object, Confess>(this, Constants.send_confession, confess);
                DependencyService.Get <IMessage>().ShortAlert("Queued for Sending");
                ChangeLoading(false);

                //close this page
                await Navigation.PopModalAsync();
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex, Logic.GetErrorProperties(ex));
                ChangeLoading(false);
            }
        }
Exemplo n.º 6
0
 public ActionResult Edit(int id)
 {
     if (iConfess.GetDetail(id).MemberID.ToString() == User.Identity.Name)
     {
         Confess confess = iConfess.GetDetail(id);
         return(View(confess));
     }
     return(View("~/Views/Common/Denied.cshtml"));
 }
Exemplo n.º 7
0
 public static async Task CreateConfess(Confess confess)
 {
     try
     {
         string url     = "confess/add";
         string content = await BaseClient.PostEntities(url, JsonConvert.SerializeObject(confess));
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 8
0
 public static async Task UpdateConfess(Confess confess, string token)
 {
     try
     {
         string url     = "confess/update";
         string content = await BaseClient.PutEntities(url, JsonConvert.SerializeObject(confess), token);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 9
0
 public static async Task UpdateConfess(Confess confess)
 {
     try
     {
         string url     = "confess/update";
         string content = await BaseClient.PutEntities(url, JsonConvert.SerializeObject(confess));
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex, Logic.GetErrorProperties(ex));
     }
 }
Exemplo n.º 10
0
        private async void Add_Tapped(object sender, RoutedEventArgs e)
        {
            if (!Logic.IsInternet())
            {
                await new MessageDialog("No INTERNET connection has been found.").ShowAsync();
                return;
            }
            if (string.IsNullOrEmpty(title_text.Text))
            {
                await new MessageDialog("Please type a Title").ShowAsync();
                return;
            }
            if (categories.SelectedItem == null)
            {
                await new MessageDialog("Please choose a Category").ShowAsync();
                return;
            }
            if (string.IsNullOrEmpty(body_text.Text))
            {
                await new MessageDialog("Please type a Body").ShowAsync();
                return;
            }
            if (body_text.Text.Length < 100)
            {
                await new MessageDialog("Please type more texts for the Body").ShowAsync();
                return;
            }

            try
            {
                ChangeLoading(true);
                Confess confess = new Confess()
                {
                    Title      = title_text.Text,
                    Body       = body_text.Text,
                    Category   = categories.SelectedItem.ToString(),
                    Owner_Guid = Logic.GetKey(),
                };
                //Save
                await Online.ConfessClass.CreateConfess(confess);

                await new MessageDialog("Published").ShowAsync();

                ChangeLoading(false);

                //call the mainpage to reload the list and  refresh
                Frame.Navigate(typeof(Homer));
            }
            catch (Exception ex)
            {
                ChangeLoading(false);
            }
        }
Exemplo n.º 11
0
            public static void UpdateConfess(Confess incoming)
            {
                Confess confes = contextLite.Confess.FindOne(d => d.Guid == incoming.Guid);

                confes.Title    = incoming.Title;
                confes.Body     = incoming.Body;
                confes.Category = incoming.Category;
                contextLite.Confess.Update(confes);

                // FilterDefinition<Confess> filter = Builders<Confess>.Filter.Eq(u => u.Guid, confess.Guid);
                // context.Confess.ReplaceOne(filter, confess);
            }
Exemplo n.º 12
0
        public static bool Email(Confess confess)
        {
            string Url = string.Format("http://www.justsay.cn/confess/Details/{0}", confess.ID);
            string msg = SMTPManager.MailSending(confess.ToEmail, confess.ToName + "你被人表白了", string.Format(ConfessEmailTemplete, confess.ToName, confess.Content, Url), "", 0);

            if (msg != "发送成功")
            {
                ToDoListBusiness.WriteLog(msg, "邮箱异常", "SMTPManager.MailSending", true);
                return(false);
            }
            return(true);
        }
Exemplo n.º 13
0
        public ActionResult Create([Bind(Include = "Content,Message,ToEmail,ToPhone,ToName,ImgUrl,FlashUrl,MusicUrl,ViewName")] Confess confess)
        {
            IMemberBusiness iMember = new MemberBusiness(new JustSayEntities());

            if (iMember.IsLimitPost(User.Identity.Name.ToInt()))
            {
                ViewData["Validate"] = true;
            }
            else
            {
                ModelState.Remove("_mvcCaptchaText");
            }
            if (ModelState.IsValid)
            {
                iConfess.Add(confess);
                //   IMemberBusiness iMember = new MemberBusiness(new JustSayEntities());
                confess.Member = iMember.GetDetail(Convert.ToInt32(User.Identity.Name));
                Relation relation = new Relation
                {
                    FromEmail = confess.Member.Email,
                    ShowName  = confess.Member.ShowName,
                    MemberID  = confess.Member.ID,
                    FromPhone = confess.Member.Phone,
                    FromName  = confess.Member.RealName,
                    ToEmail   = confess.ToEmail,
                    ToName    = confess.ToName,
                    ToPhone   = confess.ToPhone,
                };

                ViewBag.IsEmailSuccess = Inform.Email(confess);
                ViewBag.IsSMSSuccess   = false;
                ViewBag.IsSMSMsg       = "";
                if (!string.IsNullOrEmpty(confess.ToPhone))
                {
                    if (confess.Member.Score > 50)
                    {
                        ViewBag.IsSMSSuccess  = Inform.SMS(confess);
                        confess.Member.Score -= 50;
                        ViewBag.IsSmsSuccess  = true;
                    }
                    else
                    {
                        ViewBag.IsSMSMsg = "节操币不足50,请多发贴,多回贴";
                    }
                }

                ViewData["ConfessID"] = confess.ID;
                return(View("~/Views/Relation/Create.cshtml", relation));
            }

            return(View(confess));
        }
Exemplo n.º 14
0
        public static bool SMS(Confess confess)
        {
            string    Url    = string.Format("http://www.justsay.cn/confess/Details/{0}", confess.ID);
            SmsStatus status = SMSHelper.SendMsg(confess.ToPhone, string.Format(ConfessSMSTemplete, confess.ToName, Url));

            if (!status.IsSuccess)
            {
                ToDoListBusiness.WriteLog(status.ErrorMessage, "短信异常", "SMSHelper.SendMsg", true);
                return(false);
            }
            return(status.IsSuccess);
            //  return true;
        }
Exemplo n.º 15
0
        //public IActionResult Edit()
        //{
        //    ViewData["Message"] = "Your contact page.";

        //    return View();
        //}

        public async Task <IActionResult> Edit()
        {
            string guid = Request.Path.Value.Split('/').LastOrDefault();

            if (!string.IsNullOrEmpty(guid))
            {
                Confess confess = await Store.ConfessClass.FetchOneConfessByGuid(guid, GetToken(GetKey()));

                Modeller modeller = new Modeller()
                {
                    Confess = confess, ListItems = Logic.GetCategoriesLists(confess.Category)
                };
                return(View(modeller));
            }
            return(View());
        }
Exemplo n.º 16
0
        public ActionResult <Confess> FetchByGuid(string guid)
        {
            try
            {
                //prepare responses
                Confess response = Store.ConfessClass.FetchOneConfessByGuid(guid);

                //return data
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(new Confess()
                {
                });
            }
        }
Exemplo n.º 17
0
            public static async Task <Confess> FetchOneConfessByGuid(string guid, string token)
            {
                try
                {
                    string url     = $"confess/fetch/guid?guid={guid}";
                    string content = await BaseClient.GetEntities(url, token);

                    Confess data = JsonConvert.DeserializeObject <Confess>(content);
                    return(data);
                }
                catch (Exception ex)
                {
                    return(new Confess()
                    {
                    });
                }
            }
Exemplo n.º 18
0
            public static async Task <Confess> FetchOneConfessByGuid(string guid)
            {
                try
                {
                    string url     = $"confess/fetch/guid?guid={guid}";
                    string content = await BaseClient.GetEntities(url);

                    Confess data = JsonConvert.DeserializeObject <Confess>(content);
                    return(data);
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex, Logic.GetErrorProperties(ex));
                    return(new Confess()
                    {
                    });
                }
            }
Exemplo n.º 19
0
            public static List <CommentLoader> FetchComment(string guid, string key)
            {
                List <Comment> data = contextLite.Comment.Find(d => d.Confess_Guid == guid).ToList();

                //FilterDefinitionBuilder<Comment> builder = Builders<Comment>.Filter;
                //FilterDefinition<Comment> idFilter = builder.Eq(e => e.Confess_Guid, guid);
                //IFindFluent<Comment, Comment> cursor = context.Comment.Find(idFilter);
                // Find All

                //report seen
                Confess confess = ConfessClass.FetchOneConfessByGuid(guid);

                if (confess.Owner_Guid != key)
                {
                    SeenClass.Post(guid, key);
                }
                return(GetLoader(data, key));
            }
Exemplo n.º 20
0
        public ActionResult Edit([Bind(Include = "ID,Content,Message,ViewName")] Confess confess)
        {
            Confess oconfess = iConfess.GetDetail(confess.ID);

            if (oconfess.MemberID.ToString() == User.Identity.Name)
            {
                ModelState.Remove("ToEmail");
                if (ModelState.IsValid)
                {
                    oconfess.Content  = confess.Content;
                    oconfess.Message  = confess.Message;
                    oconfess.ViewName = confess.ViewName;
                    iConfess.Update(oconfess);
                    return(RedirectToAction("Details", new { id = confess.ID }));
                }
                return(View(confess));
            }
            return(View("~/Views/Common/Denied.cshtml"));
        }
Exemplo n.º 21
0
            public static ConfessLoader FetchOneConfessLoader(string guid, string senderKey)
            {
                Confess data = FetchOneConfessByGuid(guid);

                //report seen
                if (data.Owner_Guid != senderKey)
                {
                    SeenClass.Post(guid, senderKey);
                }
                // contextLite.Confess.FindOne(d => d.Guid == guid);

                //FilterDefinitionBuilder<Confess> builder = Builders<Confess>.Filter;
                //FilterDefinition<Confess> idFilter = builder.Eq(e => e.Guid, guid);

                //IFindFluent<Confess, Confess> cursor = context.Confess.Find(idFilter);

                // Find All
                return(GetConfessLoader(data, senderKey));
            }
Exemplo n.º 22
0
 public async Task UpdateConfession(string message)
 {
     //check for emptiness
     if (!string.IsNullOrEmpty(message))
     {
         Confess data   = JsonConvert.DeserializeObject <Confess>(message);
         bool    isSafe = Logic.CheckSpamFree(data.Body.ToLower());
         if (isSafe)
         {
             Store.ConfessClass.UpdateConfess(data);
             ConfessLoader confess = Store.ConfessClass.FetchOneConfessLoader(data.Guid, data.Owner_Guid);
             await Clients.All.SendAsync("ReceiveUpdateConfession", JsonConvert.SerializeObject(confess));
         }
         else
         {
             Push.NotifyOwnerOFSpam(data.Owner_Guid);
         }
     }
 }
Exemplo n.º 23
0
 public ActionResult Update([FromBody] Confess data)
 {
     try
     {
         bool isSafe = Logic.CheckSpamFree(data.Body.ToLower());
         if (isSafe)
         {
             Store.ConfessClass.UpdateConfess(data);
         }
         else
         {
             Push.NotifyOwnerOFSpam(data.Owner_Guid);
         }
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.ToString()));
     }
 }
Exemplo n.º 24
0
        public async Task <IActionResult> Add(Modeller confessed)
        {
            try
            {
                Confess confess = confessed.Confess;// new Confess();// (Confess)confessed;
                if (string.IsNullOrWhiteSpace(confess.Title) ||
                    string.IsNullOrWhiteSpace(confess.Body) ||
                    string.IsNullOrWhiteSpace(confess.Category))
                {
                    return(RedirectToActionPermanent("Index", "Home"));
                }

                confess.Owner_Guid = GetKey();
                //Save
                await Store.ConfessClass.CreateConfess(confess, GetToken(GetKey()));

                return(RedirectToActionPermanent("Index", "Home"));
            }
            catch (Exception)
            {
                return(RedirectToActionPermanent("Index", "Home"));
            }
        }
Exemplo n.º 25
0
 public static void CreateConfess(Confess confess)
 {
     confess.Id = Logical.Setter(confess.Id);
     contextLite.Confess.Insert(confess);
     //context.Confess.InsertOne(confess);
 }
Exemplo n.º 26
0
 public static void CreateConfess(Confess Confess)
 {
     contextLite.Confess.Insert(Confess);
 }
Exemplo n.º 27
0
        private async void Update_Tapped(object sender, RoutedEventArgs e)
        {
            if (!Logic.IsInternet())
            {
                await new MessageDialog("No INTERNET connection has been found.").ShowAsync();
                return;
            }
            ChangeLoading(true);
            if (string.IsNullOrEmpty(title_text.Text))
            {
                await new MessageDialog("Please type a Title").ShowAsync();
                ChangeLoading(false);
                return;
            }
            if (categories.SelectedItem == null)
            {
                await new MessageDialog("Please choose a Category").ShowAsync();
                ChangeLoading(false);
                return;
            }
            if (string.IsNullOrEmpty(body_text.Text))
            {
                await new MessageDialog("Please type a Body").ShowAsync();
                ChangeLoading(false);
                return;
            }
            if (body_text.Text.Length < 100)
            {
                await new MessageDialog("Please type more texts for the Body").ShowAsync();
                return;
            }
            try
            {
                Confess fetch = new Confess
                {
                    Title    = title_text.Text,
                    Body     = body_text.Text,
                    Category = categories.SelectedItem.ToString(),
                    Guid     = confess.Guid
                };


                //Save
                await Online.ConfessClass.UpdateConfess(fetch);

                await new MessageDialog("Updated").ShowAsync();
                ChangeLoading(false);

                //close this page
                if (Frame.CanGoBack)
                {
                    Frame.GoBack();
                }
                else
                {
                    Frame.Navigate(typeof(Homer));
                }
            }
            catch (Exception)
            {
            }
        }