// GET: Event/Details/5 public ActionResult Details(int id) { IServiceUserEvent spue = new serviceUserEvent(); Event _event = spe.GetById(id); List <EventPicture> pic = sep.GetMany(x => x.eventid == id).ToList(); ViewBag.participate = false; if (User.Identity.IsAuthenticated && spa.Get(x => x.mailAdmin == User.Identity.Name) == null) { int uid = spu.Get(x => x.username == User.Identity.Name).id; if (spue.Get(x => x.eventid == id && x.userid == uid) != null) { ViewBag.participate = spue.Get(x => x.eventid == id && x.userid == uid).participation; } } ViewBag.like = false; if (User.Identity.IsAuthenticated && spa.Get(x => x.mailAdmin == User.Identity.Name) == null) { int uid = spu.Get(x => x.username == User.Identity.Name).id; if (spue.Get(x => x.eventid == id && x.userid == uid) != null) { ViewBag.like = spue.Get(x => x.eventid == id && x.userid == uid).like; } } if (_event.hostedby == null) { ViewBag.hostedby = spo.GetById((long)_event.hostedbyid).orgname; } ViewData.Model = _event; ViewBag.pic = pic; return(View()); }
public JsonResult Like(int ide) { IServiceUserEvent spue = new serviceUserEvent(); int? uid1 = spu.Get(x => x.username == User.Identity.Name).id; UserEvent uev = new UserEvent(); if (uid1 != null) { int uid = uid1.GetValueOrDefault(); uev = spue.Get(x => x.userid == uid && x.eventid == ide); if (uev == null) { // if the user didn't like the event before spue.like(uid, ide); return(Json(new { IsOk = true, Eventid = ide, Action = "liked" })); } else { if (uev.like == false) { uev.like = true; spue.Update(uev); spue.Commit(); return(Json(new { IsOk = true, Eventid = ide, Action = "liked" })); } else { uev.like = false; spue.Update(uev); spue.Commit(); return(Json(new { IsOk = true, Eventid = ide, Action = "unlike" })); } } } else { return(Json(new { IsOk = true, Eventid = ide, Action = "false" })); } }