final
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-05-20 01:36:54 +02:00
parent beab15a7ef
commit 10c1bb008f
19 changed files with 1632 additions and 19 deletions

View File

@ -1,10 +1,12 @@
using HanyadikHetVan.DTO;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Net.Mime;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers.V2
@ -52,5 +54,41 @@ namespace HanyadikHetVan.Controllers.V2
return NotFound();
}
}
[HttpDelete("{funfactId}")]
[Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> DeleteFunFact(int funfactId)
{
var result = await _funfactService.DeleteFunFact(funfactId);
if (result)
{
return Ok(result);
}
else
{
return NotFound();
}
}
[HttpPut("{funfactId}")]
[Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FunFactDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> UpdatePause(int funfactId, [FromBody] FunFactDTO funfact)
{
try
{
var obj = await _funfactService.UpdateFunFact(funfactId, funfact);
return Ok(obj);
}
catch (Exception)
{
return NotFound();
}
}
}
}

View File

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Net.Mime;
using System.Threading.Tasks;
using System.Security.Claims;
namespace HanyadikHetVan.Controllers.V2
{
@ -25,25 +26,24 @@ namespace HanyadikHetVan.Controllers.V2
[HttpPost]
[Authorize]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WeeklyTimeSpanDTO))]
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(PauseDTO))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> AddPause([FromBody] PauseDTO pause)
{
try
{
var obj = await _pauseService.AddPause(pause);
var obj = await _pauseService.AddPause(this.User.FindFirst(ClaimTypes.NameIdentifier).Value, pause);
return CreatedAtAction(nameof(GetPauseById),new { pauseId = obj.Id } ,obj);
}
catch (Exception)
{
return BadRequest();
}
}
[HttpDelete("{pauseId}")]
[Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> DeletePause(int pauseId)

View File

@ -0,0 +1,46 @@
using HanyadikHetVan.DTO;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers.V2
{
[ApiVersion("2.0")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class UserController : Controller
{
private readonly UserService _userservice;
public UserController(UserService userservice)
{
_userservice = userservice ?? throw new ArgumentNullException(nameof(userservice));
}
[HttpPost]
[Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(UserDTO))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> UpdateWeeklyTimeSpan([FromBody] UserDTO user)
{
try
{
var userobj = await _userservice.CreateUser(user);
return Ok(userobj);
}
catch (Exception)
{
return BadRequest();
}
}
}
}

View File

@ -2,6 +2,8 @@
{
public class FunFactDTO
{
public int Id { get; set; }
public double FunFactor { get; set; }
public string Fact { get; set; }

View File

@ -16,5 +16,23 @@ namespace HanyadikHetVan.Data
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Pause>()
.HasOne(s => s.WeeklyTimeSpan)
.WithMany(s => s.Pauses)
.OnDelete(DeleteBehavior.ClientCascade);
modelBuilder.Entity<FunFact>()
.HasOne(s => s.WeeklyTimeSpan)
.WithMany(s => s.FunFacts)
.OnDelete(DeleteBehavior.ClientCascade);
modelBuilder.Entity<WeeklyTimeSpan>()
.HasOne(s => s.User)
.WithMany(s => s.WeeklyTimeSpans)
.OnDelete(DeleteBehavior.ClientCascade);
}
}
}

View File

@ -0,0 +1,383 @@
// <auto-generated />
using System;
using HanyadikHetVan.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace HanyadikHetVan.Data.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20210519232012_ChangeCascadeBehavior")]
partial class ChangeCascadeBehavior
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.6")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("HanyadikHetVan.Data.Entities.FunFact", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Fact")
.HasColumnType("nvarchar(max)");
b.Property<double>("FunFactor")
.HasColumnType("float");
b.Property<int>("WeeklyTimeSpanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("WeeklyTimeSpanId");
b.ToTable("FunFacts");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Enddate")
.HasColumnType("datetime2");
b.Property<DateTime>("Startdate")
.HasColumnType("datetime2");
b.Property<int>("WeeklyTimeSpanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("WeeklyTimeSpanId");
b.ToTable("Pauses");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("nvarchar(450)");
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetimeoffset");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("bit");
b.Property<string>("SecurityStamp")
.HasColumnType("nvarchar(max)");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("bit");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex")
.HasFilter("[NormalizedUserName] IS NOT NULL");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Startdate")
.HasColumnType("datetime2");
b.Property<string>("UserId")
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("WeeklyTimeSpans");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("nvarchar(450)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex")
.HasFilter("[NormalizedName] IS NOT NULL");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderKey")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("nvarchar(450)");
b.Property<string>("RoleId")
.HasColumnType("nvarchar(450)");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("nvarchar(450)");
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("Name")
.HasColumnType("nvarchar(450)");
b.Property<string>("Value")
.HasColumnType("nvarchar(max)");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.FunFact", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan")
.WithMany("FunFacts")
.HasForeignKey("WeeklyTimeSpanId")
.OnDelete(DeleteBehavior.ClientCascade)
.IsRequired();
b.Navigation("WeeklyTimeSpan");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan")
.WithMany("Pauses")
.HasForeignKey("WeeklyTimeSpanId")
.OnDelete(DeleteBehavior.ClientCascade)
.IsRequired();
b.Navigation("WeeklyTimeSpan");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.User", "User")
.WithMany("WeeklyTimeSpans")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.ClientCascade);
b.Navigation("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HanyadikHetVan.Data.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.User", b =>
{
b.Navigation("WeeklyTimeSpans");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b =>
{
b.Navigation("FunFacts");
b.Navigation("Pauses");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,61 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace HanyadikHetVan.Data.Migrations
{
public partial class ChangeCascadeBehavior : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "FunFacts");
migrationBuilder.DropForeignKey(
name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "Pauses");
migrationBuilder.AddForeignKey(
name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "FunFacts",
column: "WeeklyTimeSpanId",
principalTable: "WeeklyTimeSpans",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "Pauses",
column: "WeeklyTimeSpanId",
principalTable: "WeeklyTimeSpans",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "FunFacts");
migrationBuilder.DropForeignKey(
name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "Pauses");
migrationBuilder.AddForeignKey(
name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "FunFacts",
column: "WeeklyTimeSpanId",
principalTable: "WeeklyTimeSpans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId",
table: "Pauses",
column: "WeeklyTimeSpanId",
principalTable: "WeeklyTimeSpans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -286,7 +286,7 @@ namespace HanyadikHetVan.Data.Migrations
b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan")
.WithMany("FunFacts")
.HasForeignKey("WeeklyTimeSpanId")
.OnDelete(DeleteBehavior.Cascade)
.OnDelete(DeleteBehavior.ClientCascade)
.IsRequired();
b.Navigation("WeeklyTimeSpan");
@ -297,7 +297,7 @@ namespace HanyadikHetVan.Data.Migrations
b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan")
.WithMany("Pauses")
.HasForeignKey("WeeklyTimeSpanId")
.OnDelete(DeleteBehavior.Cascade)
.OnDelete(DeleteBehavior.ClientCascade)
.IsRequired();
b.Navigation("WeeklyTimeSpan");
@ -307,7 +307,8 @@ namespace HanyadikHetVan.Data.Migrations
{
b.HasOne("HanyadikHetVan.Data.Entities.User", "User")
.WithMany("WeeklyTimeSpans")
.HasForeignKey("UserId");
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.ClientCascade);
b.Navigation("User");
});

View File

@ -9,7 +9,7 @@ namespace HanyadikHetVan.Profiles
public FunFactProfile()
{
CreateMap<FunFact, FunFactDTO>();
CreateMap<FunFactDTO, FunFact>().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()).ForMember(x => x.Id, options => options.Ignore());
CreateMap<FunFactDTO, FunFact>().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpan, options => options.Ignore());
}
}
}

View File

@ -32,5 +32,30 @@ namespace HanyadikHetVan.Services
var funfact = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync();
return funfact.FunFactor;
}
public async Task<bool> DeleteFunFact(int funfactId)
{
try
{
var item = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync();
_dbContext.FunFacts.Remove(item);
await _dbContext.SaveChangesAsync();
return true;
}
catch (Exception)
{
return false;
}
}
public async Task<FunFactDTO> UpdateFunFact(int funfactId, FunFactDTO funfact)
{
var funfactentity = _mapper.Map<FunFactDTO, FunFact>(funfact);
funfactentity.Id = funfactId;
_dbContext.FunFacts.Update(funfactentity);
await _dbContext.SaveChangesAsync();
var newff = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync();
return _mapper.Map<FunFact, FunFactDTO>(newff);
}
}
}

View File

@ -27,9 +27,17 @@ namespace HanyadikHetVan.Services
return _mapper.Map<List<Pause>, List<PauseDTO>>(pauses);
}
public async Task<PauseDTO> AddPause(PauseDTO pause)
public async Task<PauseDTO> AddPause(string userId, PauseDTO pause)
{
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.UserId == userId && x.Id == pause.WeeklyTimeSpanId).FirstOrDefaultAsync();
if (wts == null)
{
throw new Exception("Not found");
}
var pauseEntity = _mapper.Map<PauseDTO, Pause>(pause);
pauseEntity.WeeklyTimeSpanId = pause.WeeklyTimeSpanId;
var obj = _dbContext.Pauses.Add(pauseEntity);
await _dbContext.SaveChangesAsync();
return _mapper.Map<Pause, PauseDTO>(obj.Entity);

View File

@ -14,23 +14,23 @@ namespace HanyadikHetVan.Services
{
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
}
public async Task<UserDTO> CreateUser(string email, string password)
public async Task<UserDTO> CreateUser(UserDTO user)
{
var newUser = new User
{
UserName = email,
Email = email,
UserName = user.Email,
Email = user.Email,
EmailConfirmed = true,
};
var result = await _userManager.CreateAsync(newUser,password);
var result = await _userManager.CreateAsync(newUser, user.Password);
if (!result.Succeeded)
{
throw new Exception("Failed to create user.");
}
return new UserDTO() { Email = email };
return new UserDTO() { Email = user.Email };
}
}
}

View File

@ -24,25 +24,25 @@ namespace HanyadikHetVan.Services
public async Task<List<WeeklyTimeSpanDTO>> GetAllWeeklyTimeSpans()
{
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).ToListAsync();
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).ToListAsync();
return _mapper.Map<List<WeeklyTimeSpan>, List<WeeklyTimeSpanDTO>>(wts);
}
public async Task<WeeklyTimeSpanDTO> GetWeeklyTimeSpan(int weeklytimespanId)
{
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync();
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync();
return _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(wts);
}
public async Task<List<PauseDTO>> GetPausesOfWeeklyTimeSpan(int weeklytimespanId)
{
var pauses = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync();
var pauses = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync();
return _mapper.Map<ICollection<Pause>, List<PauseDTO>>(pauses.Pauses);
}
public async Task<WeeklyTimeSpanDTO> GetWeeklyTimeSpanByStartdate(DateTime startTime)
{
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Startdate.Date.Equals(startTime.Date)).ToListAsync();
var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).Where(x => x.Startdate.Date.Equals(startTime.Date)).ToListAsync();
return _mapper.Map<List<WeeklyTimeSpan>, WeeklyTimeSpanDTO>(wts);
}

View File

@ -38,6 +38,7 @@ namespace HanyadikHetVan
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddTransient<WeeklyTimeSpanService>();
services.AddTransient<PauseService>();
services.AddTransient<UserService>();
services.AddTransient<FunFactService>();
services.AddTransient<HanyadikHetVanEntityService>();
services.AddTransient<HanyadikHetVanJsonService>();