Exemplo n.º 1
0
        public async Task <bool> CreateAsync(MonthlyConsumablesBindingModel model)
        {
            var rentAgreement = await this.Db
                                .FindAsync <RentAgreement>(model.rentId);

            if (rentAgreement == null)
            {
                return(false);
            }

            var monthlyConsumables = Mapper.Map <MonthlyPaymentConsumable>(model);

            rentAgreement.MonthlyConsumables
            .Add(monthlyConsumables);
            try
            {
                await this.Db.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(MonthlyConsumablesBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData.AddErrorMessage(WrongInput);
                return(this.View(model));
            }

            var isCreated = await this.consumables.CreateAsync(model);

            if (!isCreated)
            {
                return(this.BadRequest());
            }
            TempData.AddSuccessMessage("Успешно въведохте консумативи ");
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task CreateMonthlyConsumable_ShouldReturn_True_IfInputCorrect()
        {
            var db     = GetDatabase();
            var mapper = GetMapper();
            var rent   = new RentAgreement {
                Id = 1, IsActual = true
            };
            await db.RentAgreements.AddAsync(rent);

            await db.SaveChangesAsync();

            var consumabelService = new MonthlyConsumablesService(mapper, db);

            var consumableInput = new MonthlyConsumablesBindingModel
            {
                DeadLine              = new DateTime(2018, 12, 24),
                ElectricityDay        = 1,
                ElectricityNight      = 2,
                ElectricityPeak       = 3,
                PaymentForElectricity = 4,
                PaymentForWater       = 5,
                WaterReport           = 6,
                rentId = 1
            };
            //Act
            var result = await consumabelService.CreateAsync(consumableInput);

            var createdConsumable = await db.MonthlyPaymentConsumables
                                    .FirstOrDefaultAsync(x => x.ElectricityDay == 1 && x.PaymentForWater == 5);

            //Assert
            result
            .Should()
            .BeTrue();
            createdConsumable
            .Should()
            .Match <MonthlyPaymentConsumable>(x =>
                                              x.DeadLine == new DateTime(2018, 12, 24) &&
                                              x.ElectricityDay == 1 &&
                                              x.ElectricityNight == 2 &&
                                              x.ElectricityPeak == 3 &&
                                              x.PaymentForElectricity == 4 &&
                                              x.PaymentForWater == 5 &&
                                              x.WaterReport == 6);
        }