Ejemplo n.º 1
0
        public ActionResult AddToFavorites(int entityID)
        {
            try
            {
                var originalUser = this.UnitOfWork.UserRepository.Get().Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

                var originalEntity = repository.GetEntity(entityID);

                if (originalEntity == null || originalUser == null)
                    throw new Exception();

                var favorite = new favorite();
                favorite.entity_id = entityID;
                favorite.user_id = originalUser.Id;

                repository.AddFavorite(favorite);

                return Json(new { success = true });
            }
            catch
            {
                return Json(new { success = false });
            }

            return Json(new { success = false });
        }
Ejemplo n.º 2
0
        public void AddFavorite(favorite favorite)
        {
            try
            {
                entities.favorites.Add(favorite);
                Save();
            }
            catch(Exception ex)
            {

            }
        }
Ejemplo n.º 3
0
        public void DeleteFavorite(favorite favorite)
        {
            try
            {
                entities.favorites.Remove(favorite);
                Save();
            }
            catch (Exception ex)
            {

            }
        }