コード例 #1
0
        public async Task <ResponseMessage> SuggestedImageList(IdRequestViewModel model)
        {
            var article = await db.Articles.FindAsync(model.Id);

            Debug.Assert(article != null, nameof(article) + " != null");
            return(Tools.ResponseMessage.OkWithResult(article.ImageSuggests.Select(x => x.AbsoluteImageUrl).ToList()));
        }
コード例 #2
0
        public async Task <ResponseMessage> UserBoxQuestions(IdRequestViewModel model)
        {//id userpackagebox
            try
            {
                var userPackageBox = await db.UserPackageBoxes.FindAsync(model.Id);

                if (userPackageBox == null)
                {
                    LogThis.BaseLog(Request, LogLevel.Warn, Actions.UserPackageBoxQuestionsRequested, new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, model.Id },
                        { LogProperties.Message, ErrorMessages.UserPackageBoxNotFound }
                    });
                    return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.NotFound, ErrorMessages.UserPackageBoxNotFound));
                }

                switch (userPackageBox.State)
                {
                case BoxState.NotOwned:
                    LogThis.BaseLog(Request, LogLevel.Info, Actions.UserPackageBoxQuestionsRequested,
                                    new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, model.Id },
                        { LogProperties.Message, ErrorMessages.UserNotOwnedBox },
                    });
                    return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.UserStatusFaild, ErrorMessages.UserNotOwnedBox));

                case BoxState.Learning:
                    LogThis.BaseLog(Request, LogLevel.Info, Actions.UserPackageBoxQuestionsRequested, new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, model.Id },
                        { LogProperties.Message, ErrorMessages.UserPackageBoxNotLearned }
                    });
                    return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.UserStatusFaild, ErrorMessages.UserPackageBoxNotLearned));

                default:

                    LogThis.BaseLog(Request, LogLevel.Info, Actions.UserPackageBoxQuestionsRequested,
                                    new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, model.Id },
                        { LogProperties.Message, ErrorMessages.Successful },
                        { LogProperties.Count, userPackageBox.Box.Articles.Count }
                    });
                    return(Tools.ResponseMessage.OkWithResult(userPackageBox.Box.Articles.SelectMany(x => x.Questions).Select(x => new QuestionMinimalViewModel(x, User.Identity.GetUserId()))));
                }
            }
            catch (Exception e)
            {
                LogThis.BaseLog(Request, LogLevel.Error, Actions.UserPackageBoxQuestionsRequested, new Dictionary <LogProperties, object>
                {
                    { LogProperties.Error, e }
                });
                return(Tools.ResponseMessage.InternalError);
            }
        }
コード例 #3
0
        public async Task <ResponseMessage> SetAvatar(IdRequestViewModel avatarId)
        {
            try
            {
                var avatar = await _db.AvatarImages.FindAsync(avatarId.Id);

                if (avatar == null)
                {
                    LogThis.BaseLog(Request, LogLevel.Info, Actions.SetAvatarRequested,
                                    new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, avatarId.Id },
                        { LogProperties.IdType, typeof(AvatarImage) },
                        { LogProperties.Message, ErrorMessages.AvatarImageNotFound }
                    });
                    return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.NotFound,
                                               ErrorMessages.AvatarImageNotFound));
                }

                var user = _db.Users.Find(User.Identity.GetUserId());
                user.AvatarImage = avatar;
                await _db.SaveChangesAsync();

                LogThis.BaseLog(Request, LogLevel.Info, Actions.SetAvatarRequested,
                                new Dictionary <LogProperties, object>
                {
                    { LogProperties.Id, avatarId.Id },
                    { LogProperties.IdType, typeof(AvatarImage) },
                    { LogProperties.Message, ErrorMessages.Successful }
                });
                return(Tools.ResponseMessage.Ok);
            }
            catch (Exception e)
            {
                LogThis.BaseLog(Request, LogLevel.Error, Actions.SetAvatarRequested,
                                new Dictionary <LogProperties, object>
                {
                    { LogProperties.Error, e }
                });
                return(Tools.ResponseMessage.InternalError);
            }
        }
コード例 #4
0
        public async Task <ResponseMessage> Packages(IdRequestViewModel model)
        {
            string ip     = StaticTools.GetIp(Request);
            string userId = User.Identity.GetUserId();

            try
            {
                var category = await db.Catergories.FindAsync(model.Id);

                if (category == null)
                {
                    LogThis.BaseLog(Request, LogLevel.Warn, Actions.PackagesOfCategoryRequested, new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, model.Id },
                        { LogProperties.Message, ErrorMessages.RequestedCategoryNotFound }
                    });
                    return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.NotFound, ErrorMessages.RequestedCategoryNotFound));
                }

                var result = category.Packages.Select(x => new PackageMinimalViewModel(x, userId)).ToList();
                LogThis.BaseLog(Request, LogLevel.Info, Actions.PackagesOfCategoryRequested,
                                new Dictionary <LogProperties, object>
                {
                    { LogProperties.Id, model.Id },
                    { LogProperties.Count, result.Count },
                    { LogProperties.Message, ErrorMessages.Successful }
                });
                return(Tools.ResponseMessage.OkWithResult(result));
            }
            catch (Exception e)
            {
                LogThis.BaseLog(Request, LogLevel.Error, Actions.CategoriesRequested, new Dictionary <LogProperties, object>
                {
                    { LogProperties.Error, e }
                });
                return(Tools.ResponseMessage.InternalError);
            }
        }
コード例 #5
0
        public async Task <ResponseMessage> UserPackageBoxes(IdRequestViewModel model)
        {
            var z = UserManager.GenerateUserToken("sss", User.Identity.GetUserId());

            try
            {
                var package = await db.Packages.FindAsync(model.Id);

                if (package == null)
                {
                    LogThis.BaseLog(Request, LogLevel.Warn, Actions.PackageBoxesRequested, new Dictionary <LogProperties, object>
                    {
                        { LogProperties.Id, model.Id },
                        { LogProperties.Message, ErrorMessages.PackageNotFound }
                    });
                    return(new ResponseMessage(Tools.ResponseMessage.ResponseCode.NotFound, ErrorMessages.PackageNotFound));
                }

                var userId       = User.Identity.GetUserId();
                var packageBoxes = package.Boxes.Select(x => new UserBoxMinimalViewModel(x, userId)).ToList();
                LogThis.BaseLog(Request, LogLevel.Info, Actions.PackageBoxesRequested, new Dictionary <LogProperties, object>
                {
                    { LogProperties.Id, model.Id },
                    { LogProperties.Message, ErrorMessages.Successful },
                    { LogProperties.Count, packageBoxes.Count }
                });
                return(Tools.ResponseMessage.OkWithResult(packageBoxes));
            }
            catch (Exception e)
            {
                LogThis.BaseLog(Request, LogLevel.Error, Actions.CategoriesRequested, new Dictionary <LogProperties, object>
                {
                    { LogProperties.Error, e }
                });
                return(Tools.ResponseMessage.InternalError);
            }
        }