Skip to content

Commit

Permalink
Fixed ShroomsDbContext when required Modified field wasn't filled on …
Browse files Browse the repository at this point in the history
…create
  • Loading branch information
Aleksanderis committed Feb 1, 2020
1 parent 10d33eb commit 50e7c2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public async Task<UserNotificationsSettingsDto> GetWallNotificationSettings(User
.Include(x => x.Wall)
.Where(x => x.UserId == userOrg.UserId && x.Wall != null && x.Wall.OrganizationId == userOrg.OrganizationId)
.Where(x => x.Wall.Type == WallType.UserCreated || x.Wall.Type == WallType.Main)
.Select(x => new WallNotificationsDto()
.Select(x => new WallNotificationsDto
{
WallName = x.Wall.Name,
WallId = x.WallId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ p.Entity is ITrackable &&

private static void UpdateEntityMetadata(IEnumerable<DbEntityEntry> entries)
{
var now = DateTime.UtcNow;
var trackableItems = entries.Where(p => p.Entity is ITrackable);

foreach (var entry in trackableItems)
{
if (entry.Entity is ITrackable trackableEntry)
Expand All @@ -265,12 +267,13 @@ private static void UpdateEntityMetadata(IEnumerable<DbEntityEntry> entries)

if (entry.State == EntityState.Added)
{
trackableEntry.Created = DateTime.UtcNow;
trackableEntry.Created = now;
trackableEntry.Modified = now;
trackableEntry.CreatedBy = userId;
}
else if (entry.State == EntityState.Deleted || entry.State == EntityState.Modified)
{
trackableEntry.Modified = DateTime.UtcNow;
trackableEntry.Modified = now;
trackableEntry.ModifiedBy = userId;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
namespace Shrooms.API.Controllers
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using AutoMapper;
using Shrooms.DataTransferObjects.Models.Notification;
using Shrooms.Domain.Services.Notifications;
using Shrooms.EntityModels.Models.Notifications;
using Shrooms.WebViewModels.Models.Notifications;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using AutoMapper;
using Shrooms.DataTransferObjects.Models.Notification;
using Shrooms.Domain.Services.Notifications;
using Shrooms.EntityModels.Models.Notifications;
using Shrooms.WebViewModels.Models.Notifications;

namespace Shrooms.API.Controllers
{
[Authorize]
public class NotificationController : BaseController
{
private INotificationService _notificationService;
private IMapper _mapper;
private readonly INotificationService _notificationService;
private readonly IMapper _mapper;

public NotificationController(INotificationService notificationService, IMapper mapper)
{
Expand Down Expand Up @@ -52,9 +52,8 @@ private IEnumerable<NotificationViewModel> MakeCommentsStacked(IEnumerable<Notif
foreach (var item in comments)
{
var parentComment = stackedList
.Where(x => CompareSourcesIds(x.sourceIds, item.SourceIds) &&
item.Type != NotificationType.EventReminder)
.FirstOrDefault();
.FirstOrDefault(x => CompareSourcesIds(x.sourceIds, item.SourceIds) && item.Type != NotificationType.EventReminder);

if (parentComment == null)
{
stackedList.Add(_mapper.Map<NotificationViewModel>(item));
Expand All @@ -72,7 +71,7 @@ private IEnumerable<NotificationViewModel> MakeCommentsStacked(IEnumerable<Notif
return stackedList;
}

private bool CompareSourcesIds(SourcesViewModel viewModel, SourcesDto dtoModel)
private static bool CompareSourcesIds(SourcesViewModel viewModel, SourcesDto dtoModel)
{
if (viewModel.postId != dtoModel.PostId || viewModel.eventId != dtoModel.EventId || viewModel.projectId != dtoModel.ProjectId || viewModel.wallId != dtoModel.WallId)
{
Expand Down

0 comments on commit 50e7c2b

Please sign in to comment.