Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eskinderg committed Jun 5, 2024
1 parent 492f18c commit c602128
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Project.Data/ProjectDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -16,13 +16,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

//Registering dynamically all mappings that implement IEntityTypeConfiguration
//Registering dynamically all mappings that implement IEntityTypeConfiguration
modelBuilder.ApplyConfigurationsFromAssembly(
Assembly.GetExecutingAssembly(),
t => t.GetInterfaces().Any(i =>
i.IsGenericType &&
i.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>) &&
typeof(BaseEntity).IsAssignableFrom(i.GenericTypeArguments[0])));
typeof(IBaseEntity).IsAssignableFrom(i.GenericTypeArguments[0])));
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Expand Down
4 changes: 2 additions & 2 deletions Project.Model/BaseEntity.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Project.Model
{
public abstract class BaseEntity
public abstract class BaseEntity : IBaseEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
Expand Down
8 changes: 8 additions & 0 deletions Project.Model/IBaseEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Project.Model
{
public interface IBaseEntity
{
int Id { get; set; }
}
}

4 changes: 2 additions & 2 deletions Project.Model/Models/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class Note : BaseEntity
public bool? SpellCheck { get; set; }
public DateTime? PinOrder { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
public DateTime? DateArchived { get; set; }
public DateTime DateModified { get; set; }
public DateTime? DateArchived { get; set; }

}
}
4 changes: 2 additions & 2 deletions ProjectAPI/Controllers/NotesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public JsonResult Get()
public JsonResult Post([FromBody] Note model)
{
model.UserId = User.GetLoggedInUserId<Guid>();

if (ModelState.IsValid)
{
var result = UnitOfWork.Notes.Add(model);
Expand Down Expand Up @@ -74,7 +74,7 @@ public JsonResult Put([FromBody] Note model)
{
UnitOfWork.Save();
UnitOfWork.AppDbContext.Entry<Note>(updated).Reload();

return Json(Mapper.Map<NoteViewModel>(updated));
}
Response.StatusCode = StatusCodes.Status400BadRequest;
Expand Down

0 comments on commit c602128

Please sign in to comment.