CalenderHandling infered
This commit is contained in:
Binary file not shown.
BIN
MyYearlyCountings/Local.db-shm
Normal file
BIN
MyYearlyCountings/Local.db-shm
Normal file
Binary file not shown.
0
MyYearlyCountings/Local.db-wal
Normal file
0
MyYearlyCountings/Local.db-wal
Normal file
188
MyYearlyCountings/Migrations/20230703200419_refIdsInCalItems.Designer.cs
generated
Normal file
188
MyYearlyCountings/Migrations/20230703200419_refIdsInCalItems.Designer.cs
generated
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using MyYearlyCountings.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace MyYearlyCountings.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DataContext))]
|
||||||
|
[Migration("20230703200419_refIdsInCalItems")]
|
||||||
|
partial class refIdsInCalItems
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "7.0.5");
|
||||||
|
|
||||||
|
modelBuilder.Entity("MyYearlyCountings.Models.AccountRecord", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Avisering")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("Belopp")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<DateTime>("BetalDatum")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Konto")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Mottagare")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("AccountRecords");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MyYearlyCountings.Models.CalDay", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Day")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("DayComment")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("DayName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Month")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("MonthId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Year")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("CalDays");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MyYearlyCountings.Models.CalHour", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Day")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("DayId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Hour")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("HourComment")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Month")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Year")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("CalHours");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MyYearlyCountings.Models.CalMonth", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Month")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("MonthComment")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("MonthName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Year")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("YearId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("CalMonths");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MyYearlyCountings.Models.CalYear", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Year")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("YearComment")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("CalYears");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MyYearlyCountings.Models.Member", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("NickName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("PersonType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Members");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace MyYearlyCountings.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class refIdsInCalItems : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "YearId",
|
||||||
|
table: "CalMonths",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "DayId",
|
||||||
|
table: "CalHours",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "MonthId",
|
||||||
|
table: "CalDays",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "YearId",
|
||||||
|
table: "CalMonths");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "DayId",
|
||||||
|
table: "CalHours");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "MonthId",
|
||||||
|
table: "CalDays");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -66,6 +66,9 @@ namespace MyYearlyCountings.Migrations
|
|||||||
b.Property<int>("Month")
|
b.Property<int>("Month")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("MonthId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("Year")
|
b.Property<int>("Year")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
@ -83,6 +86,9 @@ namespace MyYearlyCountings.Migrations
|
|||||||
b.Property<int>("Day")
|
b.Property<int>("Day")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("DayId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("Hour")
|
b.Property<int>("Hour")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
@ -121,6 +127,9 @@ namespace MyYearlyCountings.Migrations
|
|||||||
b.Property<int>("Year")
|
b.Property<int>("Year")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("YearId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("CalMonths");
|
b.ToTable("CalMonths");
|
||||||
|
|||||||
@ -4,15 +4,15 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MyYearlyCountings.Models
|
namespace MyYearlyCountings.Models;
|
||||||
|
|
||||||
|
public class CalDay
|
||||||
{
|
{
|
||||||
public class CalDay
|
public int Id { get; set; }
|
||||||
{
|
public int MonthId { get; set; }
|
||||||
public int Id { get; set; }
|
public int Year { get; set; }
|
||||||
public int Year { get; set; }
|
public int Month { get; set; }
|
||||||
public int Month { get; set; }
|
public int Day { get; set; }
|
||||||
public int Day { get; set; }
|
public string DayName { get; set; } = string.Empty;
|
||||||
public string DayName { get; set; } = string.Empty;
|
public string DayComment { get; set; } = string.Empty;
|
||||||
public string DayComment { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ namespace MyYearlyCountings.Models
|
|||||||
public class CalHour
|
public class CalHour
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int DayId { get; set; }
|
||||||
public int Year { get; set; }
|
public int Year { get; set; }
|
||||||
public int Month { get; set; }
|
public int Month { get; set; }
|
||||||
public int Day { get; set; }
|
public int Day { get; set; }
|
||||||
|
|||||||
@ -9,6 +9,7 @@ namespace MyYearlyCountings.Models
|
|||||||
public class CalMonth
|
public class CalMonth
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int YearId { get; set; }
|
||||||
public int Year { get; set; }
|
public int Year { get; set; }
|
||||||
public int Month { get; set; }
|
public int Month { get; set; }
|
||||||
public string MonthName { get; set; } = string.Empty;
|
public string MonthName { get; set; } = string.Empty;
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Local.db">
|
<None Update="Local.db">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@ static IHostBuilder CreateHostBuilder(string[] args)
|
|||||||
services.AddScoped<ISampleRepository, SampleRepository>();
|
services.AddScoped<ISampleRepository, SampleRepository>();
|
||||||
services.AddScoped<IMemberRepository, MemberRepository>();
|
services.AddScoped<IMemberRepository, MemberRepository>();
|
||||||
services.AddScoped<IAccountRecordRepository, AccountRecordRepository>();
|
services.AddScoped<IAccountRecordRepository, AccountRecordRepository>();
|
||||||
|
services.AddScoped<ICalenderRepository, CalenderRepository>();
|
||||||
services.AddScoped<IReadingIn, ReadingIn>();
|
services.AddScoped<IReadingIn, ReadingIn>();
|
||||||
services.AddDbContext<DataContext>();
|
services.AddDbContext<DataContext>();
|
||||||
|
|
||||||
|
|||||||
143
MyYearlyCountings/Repositories/CalenderRepository.cs
Normal file
143
MyYearlyCountings/Repositories/CalenderRepository.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MyYearlyCountings.Data;
|
||||||
|
using MyYearlyCountings.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyYearlyCountings.Repositories;
|
||||||
|
|
||||||
|
public class CalenderRepository : ICalenderRepository
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ILogger<CalenderRepository> _logger;
|
||||||
|
private readonly DataContext _dataContext;
|
||||||
|
|
||||||
|
public CalenderRepository(IConfiguration configuration, ILogger<CalenderRepository> logger, DataContext dataContext)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
|
_dataContext = dataContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddYear(int year, string comment)
|
||||||
|
{
|
||||||
|
var result = false;
|
||||||
|
var exists = _dataContext.CalYears.Select(x => x.Year == year);
|
||||||
|
if (exists == null)
|
||||||
|
{
|
||||||
|
var yearRec = new CalYear() { Year = year, YearComment = comment };
|
||||||
|
var insres = _dataContext.CalYears.Add(yearRec);
|
||||||
|
_dataContext.SaveChanges();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public bool AddMonth(
|
||||||
|
int year,
|
||||||
|
int month,
|
||||||
|
string monthName,
|
||||||
|
string comment
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var result = false;
|
||||||
|
|
||||||
|
var calyear = GetYear(year);
|
||||||
|
if (calyear == null)
|
||||||
|
{
|
||||||
|
_logger.LogError($"Årspost för år {year} saknas!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = _dataContext.CalMonths.Select(x => x.Year == year && x.Month == month);
|
||||||
|
if (exists == null)
|
||||||
|
{
|
||||||
|
var monthRec = new CalMonth() { Year = year, YearId = calyear.Id, Month = month, MonthName = monthName, MonthComment = comment };
|
||||||
|
var insres = _dataContext.CalMonths.Add(monthRec);
|
||||||
|
_dataContext.SaveChanges();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddDay(
|
||||||
|
int year,
|
||||||
|
int month,
|
||||||
|
int day,
|
||||||
|
string dayName,
|
||||||
|
string comment
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var result = false;
|
||||||
|
|
||||||
|
var calmonth = GetMonth(year, month);
|
||||||
|
if (calmonth == null)
|
||||||
|
{
|
||||||
|
_logger.LogError($"Månadspost för år {year}, månad {month} saknas!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = _dataContext.CalDays.Select(x => x.Year == year && x.Day == day && x.Day == day);
|
||||||
|
if (exists == null)
|
||||||
|
{
|
||||||
|
var dayRec = new CalDay() { Year = year, Month = month, MonthId = calmonth.Id, Day = day, DayName = dayName, DayComment = comment };
|
||||||
|
var insres = _dataContext.CalDays.Add(dayRec);
|
||||||
|
_dataContext.SaveChanges();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddHour(
|
||||||
|
int year,
|
||||||
|
int month,
|
||||||
|
int day,
|
||||||
|
int hour,
|
||||||
|
string comment
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var result = false;
|
||||||
|
|
||||||
|
var calday = GetDay(year, month, day);
|
||||||
|
if (calday == null)
|
||||||
|
{
|
||||||
|
_logger.LogError($"Dagspost för år {year}, månad {month}, dag {day} saknas!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = _dataContext.CalHours.Select(x => x.Year == year && x.Month == month && x.Day == day && x.Hour == hour);
|
||||||
|
if (exists == null)
|
||||||
|
{
|
||||||
|
var hourRec = new CalHour() { Year = year, Month = month, Day = day, DayId = calday.Id, Hour = hour, HourComment = comment };
|
||||||
|
var insres = _dataContext.CalHours.Add(hourRec);
|
||||||
|
_dataContext.SaveChanges();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public CalYear? GetYear(int year)
|
||||||
|
{
|
||||||
|
return _dataContext.CalYears.FirstOrDefault(x => x.Year == year);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CalMonth? GetMonth(int year, int month)
|
||||||
|
{
|
||||||
|
return _dataContext.CalMonths.FirstOrDefault(x => x.Year == year && x.Month == month);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CalDay? GetDay(int year, int month, int day)
|
||||||
|
{
|
||||||
|
return _dataContext.CalDays.FirstOrDefault(x => x.Year == year && x.Month == month && x.Day == day);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
MyYearlyCountings/Repositories/ICalenderRepository.cs
Normal file
13
MyYearlyCountings/Repositories/ICalenderRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace MyYearlyCountings.Repositories
|
||||||
|
{
|
||||||
|
public interface ICalenderRepository
|
||||||
|
{
|
||||||
|
bool AddDay(int year, int month, int day, string dayName, string comment);
|
||||||
|
bool AddHour(int year, int month, int day, int hour, string comment);
|
||||||
|
bool AddMonth(int year, int month, string monthName, string comment);
|
||||||
|
bool AddYear(int year, string comment);
|
||||||
|
CalDay? GetDay(int year, int month, int day);
|
||||||
|
CalMonth? GetMonth(int year, int month);
|
||||||
|
CalYear? GetYear(int year);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user