Exemplo n.º 1
0
        public JsonResult RemoveTag(RemoveRequest Request)
        {
            try
            {
                using (var context = new EnrampageEntities())
                {
                    var tag = context.Tags.FirstOrDefault(t => t.Id == Request.Id);

                    if (tag == null)
                    {
                        return Json(new ApiResponse(false, "Tag not found."));
                    }

                    if (tag.UserId != CurrentUser.UserId() && !CurrentUser.Admin())
                    {
                        return Json(new ApiResponse(false, "Tag not created by you."));
                    }

                    tag.Rants.Clear();
                    context.Tags.Remove(tag);
                    context.SaveChanges();
                }

                return Json(new ApiResponse(true, "Tag removed successfully."));
            }
            catch (Exception Ex)
            {
                LogHelper.Log(Ex);
                return Json(new ApiResponse(false, "Failed to remove tag."));
            }
        }
Exemplo n.º 2
0
        public JsonResult RemoveRant(RemoveRequest Request)
        {
            try
            {
                using (var context = new EnrampageEntities())
                {
                    var rant = context.Rants.FirstOrDefault(r => r.Id == Request.Id);

                    if (rant == null)
                    {
                        return Json(new ApiResponse(false, "Rant not found."));
                    }

                    if (rant.UserId != CurrentUser.UserId() && !CurrentUser.Admin())
                    {
                        return Json(new ApiResponse(false, "Rant not post by you."));
                    }

                    rant.Tags.Clear();
                    context.Reports.RemoveRange(rant.Reports);
                    context.Rants.Remove(rant);
                    context.SaveChanges();
                }

                return Json(new ApiResponse(true, "Rant removed successfully."));
            }
            catch (Exception Ex)
            {
                LogHelper.Log(Ex);
                return Json(new ApiResponse(false, "Failed to remove rant."));
            }
        }