public async Task <IActionResult> Edit(int id, [Bind("Id,OptionName,Charge")] Haircut haircut)
        {
            if (id != haircut.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(haircut);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HaircutExists(haircut.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(haircut));
        }
예제 #2
0
        public async Task <IActionResult> Put(Haircut haircut)
        {
            await this.HaircutService.PutHaircut(haircut);

            //Console.Out.WriteLine(Barber);
            return(RedirectToAction("ListHaircuts"));
        }
        public async Task <IActionResult> Create([Bind("Id,OptionName,Charge")] Haircut haircut)
        {
            if (ModelState.IsValid)
            {
                _context.Add(haircut);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(haircut));
        }
 public List <Haircut> GetHaircuts()
 {
     using var command   = _connection.CreateCommand();
     command.Connection  = _connection;
     command.CommandText =
         $"select {Haircut.GetIdColumnName()}, {Haircut.GetZodiacIdColumnName()}, {Haircut.GetMoonDayColumnName()}, " +
         $"{Haircut.GetMoonPhaseColumnName()}, {Haircut.GetPredictionColumnName()}, {Haircut.GetIsPositiveColumnName()} " +
         $"from {Haircut.GetTableName()};";
     Console.WriteLine("Execute SQL: " + command.CommandText);
     return(Factory.CreateHaircutList(command.ExecuteReader(), this));
 }
예제 #5
0
        public async Task <Haircut> PatchHaircut(Haircut haircut)
        {
            var sendContent = new StringContent(JsonSerializer.Serialize(haircut), Encoding.UTF8, "application/json");

            using var response = await this.HttpClient.PatchAsync("api/haircut", sendContent);

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync();

            return(JsonSerializer.Deserialize <Haircut>(content, new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            }));
        }
        public async Task CreateAsync_haircutValidationSucceed_Createsloyalty()
        {
            // Arrange
            var haircut  = new HaircutUpdateModel();
            var expected = new Haircut();

            var haircutDAL = new Mock <IHaircutDAL>();

            haircutDAL.Setup(x => x.InsertAsync(haircut)).ReturnsAsync(expected);

            var haircutService = new HaircutService(haircutDAL.Object);

            // Act
            var result = await haircutService.CreateAsync(haircut);

            // Assert
            result.Should().Be(expected);
        }
        public async Task ValidateAsync_haircutExists_DoesNothing()
        {
            // Arrange
            var haircutContainer = new Mock <IHaircutContainer>();

            var haircut         = new Haircut();
            var haircutDAL      = new Mock <IHaircutDAL>();
            var haircutIdentity = new Mock <IHaircutIdentity>();

            haircutDAL.Setup(x => x.GetAsync(haircutIdentity.Object)).ReturnsAsync(haircut);

            var haircutGetService = new HaircutService(haircutDAL.Object);

            // Act
            var action = new Func <Task>(() => haircutGetService.ValidateAsync(haircutContainer.Object));

            // Assert
            await action.Should().NotThrowAsync <Exception>();
        }
 public void SaveOrUpdate(Haircut haircut)
 {
     using var command   = _connection.CreateCommand();
     command.Connection  = _connection;
     command.CommandText =
         $"update {Haircut.GetTableName()} " +
         $"set {Haircut.GetZodiacIdColumnName()} = :zodiacId, " +
         $"{Haircut.GetMoonDayColumnName()} = :moonDay, " +
         $"{Haircut.GetMoonPhaseColumnName()} = :moonPhase, " +
         $"{Haircut.GetPredictionColumnName()} = :prediction, " +
         $"{Haircut.GetIsPositiveColumnName()} = :isPositive " +
         $"where {Haircut.GetIdColumnName()} = :id;";
     command.Parameters.AddWithValue("zodiacId", (int)haircut.Zodiac.Type);
     command.Parameters.AddWithValue("moonDay", haircut.MoonDay);
     command.Parameters.AddWithValue("moonPhase", haircut.MoonPhase);
     command.Parameters.AddWithValue("prediction", haircut.Prediction);
     command.Parameters.AddWithValue("isPositive", haircut.IsPositive);
     command.Parameters.AddWithValue("id", haircut.Id);
     Console.WriteLine("Execute SQL: " + command.CommandText);
     command.ExecuteNonQuery();
 }
        public async Task ValidateAsync_haircutNotExists_ThrowsError()
        {
            // Arrange
            var fixture = new Fixture();
            var id      = fixture.Create <int>();

            var haircutContainer = new Mock <IHaircutContainer>();

            haircutContainer.Setup(x => x.HaircutId).Returns(id);
            var haircutIdentity = new Mock <IHaircutIdentity>();
            var haircut         = new Haircut();
            var haircutDAL      = new Mock <IHaircutDAL>();

            haircutDAL.Setup(x => x.GetAsync(haircutIdentity.Object)).ReturnsAsync((Haircut)null);

            var haircutGetService = new HaircutService(haircutDAL.Object);

            // Act
            var action = new Func <Task>(() => haircutGetService.ValidateAsync(haircutContainer.Object));
            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>($"Haircut not found by id {id}");
        }
예제 #10
0
 public void SaveOrUpdate(Haircut haircut)
 {
     GetDatabaseConnection().SaveOrUpdate(haircut);
 }
예제 #11
0
파일: Program.cs 프로젝트: prawniie/Samurai
        private static void AddOneSamuraiWithRelatedData()
        {
            var context = new SamuraiContext();

            var haircut = new Haircut {
                Name = "Short"
            };
            var secretIdentity = new SecretIdentity {
                Name = "Harry Potter"
            };

            var quoteType = new QuoteType {
                Name = "Lame"
            };
            var listOfQuotes = new List <Quote> {
                new Quote {
                    Text = "Friends come first", Type = quoteType
                }, new Quote {
                    Text = "I'm a wizard", Type = quoteType
                }
            };

            var battleEvents = new List <BattleEvent>
            {
                new BattleEvent {
                    Description = "The tribe GoronsFTW initiated the first attack", Summary = "The tribe GoronsFTW won this event", TimeOfEvent = new DateTime(1430, 3, 20)
                }
            };

            var battleLog = new BattleLog
            {
                Name         = "Goron War log",
                BattleEvents = battleEvents
            };

            var battle1 = new Battle
            {
                Name        = "The Goron War",
                Description = "The disagreements between the leaders of the Gorons eventually led to the civil war of the Gorons",
                Brutal      = true,
                StartDate   = new DateTime(1430, 3, 16),
                EndDate     = new DateTime(1432, 5, 20),
                BattleLog   = battleLog
            };

            List <Battle> samuraiBattles = new List <Battle>();

            samuraiBattles.Add(battle1);

            var samurai = new Samurai
            {
                Name           = "Arnold",
                Haircut        = haircut,
                SecretIdentity = secretIdentity,
                Quotes         = listOfQuotes,
                Battles        = samuraiBattles
            };

            context.Samurais.Add(samurai);

            var samuraiBattle = new SamuraiBattle
            {
                Samurai = samurai,
                Battle  = battle1
            };

            context.SamuraiBattles.Add(samuraiBattle); //borde väl inte behöva göra detta manuellt? Får det att fungera iallafall
            context.SaveChanges();
        }