Esempio n. 1
0
        public static int AddComment(Com.Comment comment)
        {
            try
            {
                using (var ent = DB.Entity)
                {
                    ent.Comments.Add(comment);
                    ent.SaveChanges();

                    return(comment.ComID);
                }
            }
            catch (Exception e)
            {
                Log.DoLog(Com.Common.Action.AddComment, "", -100, e.Message);
                return(-100);
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> PostComment()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(StatusCode(HttpStatusCode.UnsupportedMediaType));
                }

                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                Com.Comment mComment = new Com.Comment();

                foreach (var itemContent in filesReadToProvider.Contents)
                {
                    if (itemContent.Headers.ContentDisposition.Name == "Object")
                    {
                        var jsonString = await itemContent.ReadAsStringAsync();

                        var serializer = new JavaScriptSerializer();
                        mComment = serializer.Deserialize <Com.Comment>(jsonString);

                        int ResAdd = BLL.Feedback.AddComment(mComment);
                        //TODO: Add to product rate.
                        if (ResAdd < 0)
                        {
                            return(BadRequest());
                        }
                    }

                    else
                    {
                        return(BadRequest());
                    }
                }

                return(Ok());
            }
            catch (Exception ee)
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostComment, "", -400, ee.Message); }).Start();
                return(BadRequest());
            }
        }
Esempio n. 3
0
        //public static bool UpdateComment(Com.Comment comment)
        //{
        //    try
        //    {
        //        using (var ent = DB.Entity)
        //        {
        //            ent.Comments.Attach(comment);
        //            var Entry = ent.Entry(comment);
        //            Entry.Property(ex => ex.Round).IsModified = true;
        //            Entry.Property(ex => ex.Info).IsModified = true;
        //            ent.SaveChanges();
        //            return true;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        Log.DoLog(Com.Common.Action.UpdateComment, comment.ComID.ToString(), -100, e.Message);
        //        return false;
        //    }
        //}

        public static bool DeleteComment(int ComID)
        {
            try
            {
                using (var ent = DB.Entity)
                {
                    Com.Comment comment = new Com.Comment()
                    {
                        ComID = ComID
                    };
                    ent.Comments.Attach(comment);
                    ent.Comments.Remove(comment);
                    ent.SaveChanges();
                }

                return(true);
            }
            catch (Exception e)
            {
                Log.DoLog(Com.Common.Action.DeleteComment, ComID.ToString(), -100, e.Message);
                return(false);
            }
        }