public JsonResult SetMark(long userId,
                                  UserLanguages userLanguages,
                                  KnowledgeMark mark,
                                  TrainerItem item,
                                  RepetitionType repetitionType = RepetitionType.All)
        {
            var itemDataType = (KnowledgeDataType)(item != null ? item.DataType : int.MinValue);

            if (IsInvalid(userId, userLanguages) || EnumValidator.IsInvalid(mark) || item == null ||
                IdValidator.IsInvalid(item.DataId) || EnumValidator.IsInvalid(itemDataType) ||
                EnumValidator.IsInvalid(repetitionType))
            {
                //TODO: писать сообщение
                return(JsonResultHelper.Error());
            }

            IUserRepetitionIntervalQuery userRepetitionIntervalQuery = CreateUserRepetitionIntervalQuery(userId,
                                                                                                         repetitionType);

            var repetitionInterval = new UserRepetitionIntervalItem
            {
                DataId = item.DataId, DataType = itemDataType, SourceType = KnowledgeSourceType
            };

            var trainerHelper = new TrainerHelper(userRepetitionIntervalQuery, userLanguages);

            return(trainerHelper.SetMark(Request, mark, repetitionInterval));
        }
Exemplo n.º 2
0
        public Language GetByShortName(LanguageShortName shortName)
        {
            if (EnumValidator.IsInvalid(shortName) || shortName == LanguageShortName.Unknown)
            {
                return(null);
            }

            LoadLanguages();
            Language result;

            return(_languagesByShortNames.TryGetValue(shortName, out result) ? result : null);
        }
Exemplo n.º 3
0
        public JsonResult GetExistenceIds(long userId, List <long> ids, KnowledgeDataType dataType)
        {
            /*             List<long> ids = new List<long>();
             * KnowledgeDataType dataType = KnowledgeDataType.SentenceTranslation;*/
            List <long> parsedIds = ids != null?ids.Where(IdValidator.IsValid).ToList() : new List <long>(0);

            if (IdValidator.IsInvalid(userId) || EnumerableValidator.IsEmpty(parsedIds) ||
                EnumValidator.IsInvalid(dataType))
            {
                return(JsonResultHelper.Error(INVALID_DATA));
            }

            IUserKnowledgeQuery userKnowledgeQuery = CreateUserKnowledgeQuery(userId);
            List <long>         existenceIds       = userKnowledgeQuery.GetExistenceIds(parsedIds, dataType);

            return(JsonResultHelper.GetUnlimitedJsonResult(existenceIds));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Банит пользователя
        /// </summary>
        /// <example>localhost/StudyLanguages/Service/BanUser?userId=59&browser=Firefox&userIp=::1&sectionId=UserTasks&banType=Today</example>
        /// <returns></returns>
        public EmptyResult BanUser()
        {
            string dirtyUserId    = Request.Params["userId"];
            string dirtySectionId = Request.Params["sectionId"];
            string dirtyBanType   = Request.Params["banType"];
            string userIp         = Request.Params["userIp"];
            string browser        = Request.Params["browser"];

            string remoteClientIp = RemoteClientHelper.GetClientIpAddress(Request);

            if (string.IsNullOrEmpty(remoteClientIp) || !remoteClientIp.Equals("176.214.39.34"))
            {
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                    "ServiceController.BanUser кто-то попытался забанить пользователя!!! Настройки: userId={0}, sectionId={1}, banType={2}, userIp={3}, browser={4}",
                    dirtyUserId, dirtySectionId, dirtyBanType, userIp, browser);
                return(new EmptyResult());
            }

            RepositoryFactory repositoryFactory = WebSettingsConfig.Instance.GetRepositoryFactory();
            BanRepository     banRepository     = repositoryFactory.GetBanRepository();

            SectionId sectionId;
            BanType   banType;
            long      userId;

            if (!Enum.TryParse(dirtySectionId, true, out sectionId) || EnumValidator.IsInvalid(sectionId) ||
                !Enum.TryParse(dirtyBanType, true, out banType) || EnumValidator.IsInvalid(banType) ||
                !long.TryParse(dirtyUserId, out userId) || string.IsNullOrEmpty(userIp) ||
                string.IsNullOrEmpty(browser))
            {
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                    "ServiceController.BanUser НЕ УДАЛОСЬ распрасить данные!!! Настройки: userId={0}, sectionId={1}, banType={2}, userIp={3}, browser={4}",
                    dirtyUserId, dirtySectionId, dirtyBanType, userIp, browser);
                return(new EmptyResult());
            }

            if (!banRepository.AddBan(sectionId, banType, userId, userIp, browser))
            {
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                    "ServiceController.BanUser НЕ УДАЛОСЬ забанить пользователя!!! Настройки: userId={0}, sectionId={1}, banType={2}, userIp={3}, browser={4}",
                    userId, sectionId, banType, userIp, browser);
            }

            return(new EmptyResult());
        }
Exemplo n.º 5
0
        public VideoForUser GetOrCreate(VideoType type, VideoForUser videoForUser, byte[] image, int?rating)
        {
            if (EnumValidator.IsInvalid(type) || videoForUser == null || string.IsNullOrWhiteSpace(videoForUser.Title) ||
                string.IsNullOrWhiteSpace(videoForUser.HtmlCode)
                /*|| EnumerableValidator.IsNullOrEmpty(videoForUser.Sentences)*/)
            {
                return(null);
            }

            byte         parsedVideoType = (byte)type;
            VideoForUser result          = null;

            Adapter.ActionByContext(c => {
                Data.Video.Video video = GetOrCreateVideo(videoForUser, image, rating, parsedVideoType, c);
                long videoId           = video.Id;
                if (IdValidator.IsInvalid(videoId))
                {
                    return;
                }

                DeleteVideoSentences(c, videoId);

                result    = new VideoForUser(video);
                int order = 1;
                foreach (var sentence in videoForUser.Sentences)
                {
                    var videoSentence = new VideoSentence {
                        VideoId     = videoId,
                        Source      = sentence.Item1,
                        Translation = sentence.Item2,
                        Order       = order++
                    };
                    c.VideoSentence.Add(videoSentence);
                }
                c.SaveChanges();
            });

            return(result);
        }
Exemplo n.º 6
0
 public bool IsInvalid(UserKnowledgeItem knowledgeItem)
 {
     return(IdValidator.IsInvalid(_userId) || IdValidator.IsInvalid(_languageId) || knowledgeItem == null ||
            IdValidator.IsInvalid(knowledgeItem.DataId) ||
            EnumValidator.IsInvalid(knowledgeItem.DataType));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Добавляет купленный товар и создает платеж
        /// </summary>
        /// <param name="purchasedGoodsForUser">данные о купленном товаре</param>
        /// <returns>true - купленный товар и платеж успешно добавлены, false - купленный товар и платеж не удалось добавить</returns>
        public long WantToBuyGoods <T>(PurchasedGoodsForUser <T> purchasedGoodsForUser)
        {
            if (purchasedGoodsForUser == null || purchasedGoodsForUser.Price <= 0 ||
                EnumValidator.IsInvalid(purchasedGoodsForUser.GoodsId))
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PurchasedGoodsQuery.WantToBuyGoods. Не удалось сохранить платежку. {0}",
                                            purchasedGoodsForUser != null
                                                ? "Некорректная цена: " + purchasedGoodsForUser.Price
                                                : "purchasedGoodsForUser == null");
                return(IdValidator.INVALID_ID);
            }

            string serializedGoods;

            try {
                serializedGoods = JsonConvert.SerializeObject(purchasedGoodsForUser.Goods);
            } catch (Exception e) {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PurchasedGoodsQuery.WantToBuyGoods. Товар с уникальным идентификатором {0} не удалось сериализовать из типа {1}. Исключение: {2}",
                                            purchasedGoodsForUser.UniqueDownloadId, typeof(T).FullName, e);
                return(IdValidator.INVALID_ID);
            }

            long result = IdValidator.INVALID_ID;

            Adapter.Transaction(c => {
                var payment = new Payment {
                    Price        = purchasedGoodsForUser.Price,
                    Status       = PaymentStatus.InProcess,
                    Description  = purchasedGoodsForUser.FullDescription,
                    UserId       = purchasedGoodsForUser.UserId,
                    CreationDate = DateTime.Now,
                    PaymentDate  = new DateTime().GetDbDateTime(),
                    System       = purchasedGoodsForUser.PaymentSystem
                };
                c.Payment.Add(payment);
                c.SaveChanges();

                if (IdValidator.IsInvalid(payment.Id))
                {
                    LoggerWrapper.RemoteMessage(LoggingType.Error,
                                                "PurchasedGoodsQuery.WantToBuyGoods. Не удалось сохранить платежку. UniqueDownloadId={0}, UserId={1}, Price={2}, Description={3}",
                                                purchasedGoodsForUser.UniqueDownloadId, purchasedGoodsForUser.UserId,
                                                purchasedGoodsForUser.Price, purchasedGoodsForUser.FullDescription);
                    return(false);
                }

                var purchasedGoods = new PurchasedGoods {
                    UserId             = purchasedGoodsForUser.UserId,
                    Price              = purchasedGoodsForUser.Price,
                    Goods              = serializedGoods,
                    LanguageId         = purchasedGoodsForUser.LanguageId,
                    UniqueDownloadId   = purchasedGoodsForUser.UniqueDownloadId,
                    FullDescription    = purchasedGoodsForUser.FullDescription,
                    ShortDescription   = purchasedGoodsForUser.ShortDescription,
                    PaymentId          = payment.Id,
                    PurchaseDate       = DateTime.Now,
                    PostToCustomerDate = new DateTime().GetDbDateTime(),
                    Status             = PurchasedStatus.WaitPayment,
                    GoodsId            = (byte)purchasedGoodsForUser.GoodsId
                };
                c.PurchasedGoods.Add(purchasedGoods);
                c.SaveChanges();

                bool innerResult = IdValidator.IsValid(purchasedGoods.Id);
                if (innerResult)
                {
                    result = payment.Id;
                }
                else
                {
                    LoggerWrapper.RemoteMessage(LoggingType.Error,
                                                "PurchasedGoodsQuery.WantToBuyGoods. Не удалось сохранить купленные товары. PaymentId={0}, UniqueDownloadId={1}, UserId={2}, Price={3}, Description={4}, LanguageId={5}",
                                                payment.Id, purchasedGoodsForUser.UniqueDownloadId,
                                                purchasedGoodsForUser.UserId,
                                                purchasedGoodsForUser.Price, purchasedGoodsForUser.FullDescription,
                                                purchasedGoodsForUser.LanguageId);
                }
                return(innerResult);
            });
            return(result);
        }