コード例 #1
0
        private static MethodResult checkIfImageIsCorrect(Image img)
        {
            MethodResult result = MethodResult.Success;

            if (img.Size.Width > 450 || img.Size.Height > 450)
            {
                result.AddError("Picture can have max dimensions of 450x450");
            }

            if (Math.Abs(1.0 - img.Size.Width / (double)img.Size.Height) > 0.5)
            {
                result.AddError("Picture have wrong ratio!");
            }
            return(result);
        }
コード例 #2
0
        public ActionResult ChangeTranslations(List <EditTranslationViewModel> translations)
        {
            MethodResult globalResult = new MethodResult();

            foreach (var vm in translations)
            {
                var translation = unit.FlashcardTranslationRepository.GetById(vm.TranslationID);

                var result = flashcardTranslationService.CanChangeTranslation(translation, vm.Translation, vm.Pronounciation, vm.Significance);
                if (result.IsError)
                {
                    globalResult.AddError($"Translation {vm.TranslationID} - {result.Errors[0]}");
                }
            }

            if (globalResult.IsError)
            {
                return(RedirectBackWithError(globalResult));
            }

            foreach (var vm in translations)
            {
                var translation = unit.FlashcardTranslationRepository.GetById(vm.TranslationID);
                flashcardTranslationService.ChangeTranslation(translation, vm.Translation, vm.Pronounciation, vm.Significance);
                AddSuccess($"Translation {translation.ID} has been changed!");
            }

            return(RedirectBack());
        }
コード例 #3
0
        public MethodResult HaveEnoughMoneyToBuy(MarketOffer offer, Entity buyer, int amount)
        {
            MethodResult result = MethodResult.Success;

            var cost = GetOfferCost(offer, buyer, amount);

            var localMoney = walletService.GetWalletMoney(buyer.WalletID, offer.CurrencyID);

            if (localMoney.Amount < cost.BasePrice + cost.ImportTax + cost.VatCost)
            {
                result.AddError("You do not have enough money!");
            }

            if (cost.ExportTax > 0)
            {
                var exportMoney = walletService.GetWalletMoney(buyer.WalletID, cost.ExportCurrencyID);
                if (exportMoney.Amount < cost.ExportTax)
                {
                    result.AddError("You do not have enough money!");
                }
            }

            return(result);
        }
コード例 #4
0
        public static MethodResult ChackIfAvatarIsCorrectImage(HttpPostedFileBase file)
        {
            var tempPath = Path.GetTempFileName();

            file.SaveAs(tempPath);
            MethodResult result = MethodResult.Success;

            using (var img = Image.FromFile(tempPath))
            {
                if (img.Size.Width != 150 || img.Size.Height != 150)
                {
                    result.AddError("Final picture must have dimensions of 150x150 pixels!");
                }
            }

            return(result);
        }
コード例 #5
0
ファイル: SessionTests.cs プロジェクト: blendiahmetaj1/SUPSUP
        private MethodResult homeTest()
        {
            var options = new FirefoxOptions();

            if (isHeadless)
            {
                options.AddArgument("headless");
            }
            var driver = new FirefoxDriver(options);

            var naviger = new SociatisNaviger(driver, "test2", "abc", "http://soctest.sociatis.net");

            DateTime now = DateTime.Now;

            try
            {
                while (true)
                {
                    naviger.GotoHome();
                    var bodyText = driver.FindElement(By.TagName("body")).Text;
                    Assert.DoesNotContain(("Store update, insert, or delete statement"), bodyText);

                    if ((DateTime.Now - now).Seconds > 25)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                lock (ConcurrentHomeTestsResults)
                    ConcurrentHomeTestsResults.AddError(e.Message);
                return(new MethodResult(e.Message));
            }
            finally
            {
                driver.Close();
            }

            return(MethodResult.Success);
        }