From d015f2f64109a5f32fd0e9cea7ee26260681c70f Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 4 Feb 2021 09:40:49 +0330 Subject: [PATCH] #72 removing RUserNotificationViewModel constructor --- .../ViewModels/RUserNotificationViewModel.cs | 12 ------ RSecurityBackend/RSecurityBackend.xml | 6 --- .../Implementation/RNotificationService.cs | 40 ++++++++++++++++--- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/RSecurityBackend/Models/Notification/ViewModels/RUserNotificationViewModel.cs b/RSecurityBackend/Models/Notification/ViewModels/RUserNotificationViewModel.cs index 724c492c..c3181303 100644 --- a/RSecurityBackend/Models/Notification/ViewModels/RUserNotificationViewModel.cs +++ b/RSecurityBackend/Models/Notification/ViewModels/RUserNotificationViewModel.cs @@ -7,18 +7,6 @@ namespace RSecurityBackend.Models.Notification.ViewModels /// public class RUserNotificationViewModel { - /// - /// constructor - /// - /// - public RUserNotificationViewModel(RUserNotification src) - { - Id = src.Id; - DateTime = src.DateTime; - Status = src.Status; - Subject = src.Subject; - HtmlText = src.HtmlText; - } /// /// Id /// diff --git a/RSecurityBackend/RSecurityBackend.xml b/RSecurityBackend/RSecurityBackend.xml index edb4a55e..81ae78b3 100644 --- a/RSecurityBackend/RSecurityBackend.xml +++ b/RSecurityBackend/RSecurityBackend.xml @@ -2009,12 +2009,6 @@ User Notification - - - constructor - - - Id diff --git a/RSecurityBackend/Services/Implementation/RNotificationService.cs b/RSecurityBackend/Services/Implementation/RNotificationService.cs index c905c558..7f755f8f 100644 --- a/RSecurityBackend/Services/Implementation/RNotificationService.cs +++ b/RSecurityBackend/Services/Implementation/RNotificationService.cs @@ -38,7 +38,17 @@ namespace RSecurityBackend.Services.Implementation }; _context.Notifications.Add(notification); await _context.SaveChangesAsync(); - return new RServiceResult(new RUserNotificationViewModel(notification)); + return new RServiceResult + ( + new RUserNotificationViewModel() + { + Id = notification.Id, + DateTime = notification.DateTime, + Status = notification.Status, + Subject = notification.Subject, + HtmlText = notification.HtmlText + } + ); } catch (Exception exp) { @@ -61,7 +71,18 @@ namespace RSecurityBackend.Services.Implementation notification.Status = notification.Status == NotificationStatus.Unread ? NotificationStatus.Read : NotificationStatus.Unread; _context.Notifications.Update(notification); await _context.SaveChangesAsync(); - return new RServiceResult(new RUserNotificationViewModel(notification)); + return new RServiceResult + ( + new RUserNotificationViewModel() + { + Id = notification.Id, + DateTime = notification.DateTime, + Status = notification.Status, + Subject = notification.Subject, + HtmlText = notification.HtmlText + } + + ); } catch (Exception exp) { @@ -139,9 +160,18 @@ namespace RSecurityBackend.Services.Implementation return new RServiceResult ( await _context.Notifications - .Where(n => n.UserId == userId) - .OrderByDescending(n => n.DateTime) - .Select(n => new RUserNotificationViewModel(n)) + .Where(notification => notification.UserId == userId) + .OrderByDescending(notification => notification.DateTime) + .Select(notification => + new RUserNotificationViewModel() + { + Id = notification.Id, + DateTime = notification.DateTime, + Status = notification.Status, + Subject = notification.Subject, + HtmlText = notification.HtmlText + } + ) .ToArrayAsync() ); }