public void Unlike(int id) { using (var db = new DB_9BA48E_xmldbEntities()) { if (db.Connection.FirstOrDefault(c => c.Connection_Id == id) != null) { var user = CompAgri.Common.UserUtils.GetUser(Request); var opinion = db.UserOpinions.FirstOrDefault(uo => uo.Connection_Id == id && uo.User_Id == user.User_Id); if (opinion != null) { opinion.Opinion = false; } else { opinion = new UserOpinion { Connection_Id = id, User_Id = user.User_Id, Opinion = false }; db.UserOpinions.Add(opinion); } db.SaveChanges(); } else { throw new HttpResponseException(HttpStatusCode.NotFound); } } }
public static User GetUser(this HttpRequestMessage request) { var token = GetUserToken(request); if (token == null) { return(null); } using (var db = new DB_9BA48E_xmldbEntities()) { return(db.User.Include("UserProfile").FirstOrDefault(u => u.Token == token)); } }