public JsonResult SetLike(string id)
 {
     try
     {
         using (LikeContext content = new LikeContext())
         {
             Page page = content.Pages.FirstOrDefault(p => p.Name == id);
             Like like = new Like
             {
                 LkDateTime = DateTime.Now,
                 PageId     = page != null ? page.Id : 0
             };
             content.Likes.Add(like);
             content.SaveChanges();
             return(Json(new
             {
                 Message = "Ok",
                 Status = true
             }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new
         {
             Message = ex.Message,
             Status = false
         }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #2
0
 public JsonResult SetLike(string id)
 {
     try
     {
         using (LikeContext content = new LikeContext())
         {
             Page page = content.Pages.FirstOrDefault(p => p.Name == id); // получаем ссылку на страницу
             Like like = new Like                                         // создаём объект-лайк
             {
                 LkDateTime = DateTime.Now,
                 PageId     = page != null ? page.Id : 0
             };
             content.Likes.Add(like);                                    // добавляем лайк в набор сущностей
             content.SaveChanges();                                      // сохраняем в базу данных
             return(Json(new                                             // возварщаем json-объект
             {
                 Message = "Ok",
                 Status = true
             }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)                                                 // обработка исключения
     {
         return(Json(new
         {
             Message = ex.Message,                                       // возварщаем json-объект
             Status = false                                              // с информацией об ошибке
         }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Adds like for page, if it does not exist already.
        /// </summary>
        /// <param name="pageName"></param>
        /// <param name="userName"></param>
        /// <returns>Count of page likes by all users</returns>
        public static int AddPageLike(string pageName, string userName)
        {
            if (string.IsNullOrWhiteSpace(pageName))
            {
                throw new ArgumentNullException(nameof(pageName), "Parameter cannot be null");
            }
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException(nameof(userName), "Parameter cannot be null");
            }

            pageName = pageName.Trim();
            userName = userName.Trim();

            try
            {
                using (var context = new LikeContext())
                {
                    if (!context.UserLikes.Any(x => x.PageName.ToLower() == pageName.ToLower() && x.UserName.ToLower() == userName.ToLower()))
                    {
                        context.UserLikes.Add(new UserLike(pageName, userName));
                        context.SaveChanges();

                        return(context.UserLikes.Count(x => x.PageName.ToLower() == pageName.ToLower()));
                    }
                }
            }
            catch (Exception e)
            {
                //log error
            }

            return(-1);
        }
Beispiel #4
0
        /// <summary>
        /// Retrieves list of UserNames that liked the specified page
        /// </summary>
        /// <param name="pageName">name of page</param>
        /// <returns>List of UserName</returns>
        public static List <string> GetPageLikes(string pageName)
        {
            if (string.IsNullOrWhiteSpace(pageName))
            {
                throw new ArgumentNullException(nameof(pageName), "Parameter cannot be null");
            }

            pageName = pageName.Trim();


            List <string> userNameList = new List <string>();

            try
            {
                using (var context = new LikeContext())
                {
                    userNameList = context.UserLikes.Where(x => x.PageName.ToLower() == pageName).Select(x => x.UserName).ToList();
                }
            }
            catch (Exception e)
            {
                //log error
            }

            return(userNameList);
        }
Beispiel #5
0
 public CollectionController(LikeContext likeContext, CommentContext commentContext, CollectionContext context, ItemContext itemContext, UserManager <User> userManager)
 {
     _itemContext       = itemContext;
     _collectionContext = context;
     _userManager       = userManager;
     _commentContext    = commentContext;
     _likeContext       = likeContext;
 }
Beispiel #6
0
 public ItemController(TagContext tagContext, LikeContext likeContext, ItemContext context, CollectionContext collectionContext, UserManager <User> userManager, CommentContext commentContext)
 {
     _collectionContext = collectionContext;
     _itemContext       = context;
     _userManager       = userManager;
     _commentContext    = commentContext;
     _likeContext       = likeContext;
     _tagContext        = tagContext;
 }
 public AjaxApiPostController(
     UserManager <UserIndentity> userManager,
     SignInManager <UserIndentity> signInManager,
     ILogger <AjaxApiPostController> logger,
     PostContext postContext,
     TagContext tagContext,
     LikeContext LikeContext)
 {
     this._userManager   = userManager;
     this._signInManager = signInManager;
     this._logger        = logger;
     this._postContext   = postContext;
     this._tagContext    = tagContext;
     this._likeContext   = LikeContext;
 }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            ConfigureConsul(services);

            var secret = "eBCatxoffIIq6ESdrDZ8LKI3zpxhYkYM";
            var key    = Encoding.ASCII.GetBytes(secret);

            services.AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuerSigningKey = true,
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddAuthorization();

            services.AddMessagePublishing("LikeService", builder =>
            {
                builder.WithHandler <ForgetUserMessageHandler>("ForgetUserMessage");
                builder.WithHandler <DeleteTweetMessageHandler>("DeleteTweetMessage");
                builder.WithHandler <UnApproveTweetMessageHandler>("UnApproveTweetMessage");
            });

            var config = new ServerConfig();

            Configuration.Bind(config);

            var likeContext = new LikeContext(config.MongoDB);
            var repo        = new LikeRepository(likeContext);

            services.AddSingleton <ILikeRepository>(repo);

            services.AddScoped <ILikeService, Services.LikeService>();
        }
 public GetLikeByIdsQueryHandler(LikeContext likeContext)
 {
     LikeContext = likeContext;
 }
Beispiel #10
0
 public BrightController(LikeContext context)
 {
     _context = context;
 }
Beispiel #11
0
 public LikeRepository(LikeContext context)
 {
     _context = context;
 }
Beispiel #12
0
 public GetFullLikeByIdQueryHandler(LikeContext likeContext)
 {
     LikeContext = likeContext;
 }
Beispiel #13
0
 public GetLikesByIdPersonAndIdOwnerQueryHandler(LikeContext likeContext)
 {
     LikeContext = likeContext;
 }
 public CreateLikeHandler(LikeContext likeContext)
 {
     LikeContext = likeContext;
 }
 public LikesController(LikeContext db)
 {
     context = db;
 }
Beispiel #16
0
 public UpdateLikeHandler(LikeContext likeContext, IMediator mediator)
 {
     LikeContext = likeContext;
     _mediator   = mediator;
 }
Beispiel #17
0
 public UserController(LikeContext context)
 {
     _context = context;
 }