public static void CreateUser(WebmailContext context, User user) { var entity = new Database.POCO.User() { Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, Role = user.Role }; context.Users.Add(entity); context.SaveChanges(); }
public static Group CreateGroup(WebmailContext context, string name, Database.POCO.User admin, List <Database.POCO.User> members = null) { var group = new Database.POCO.Group() { Name = name, Admin = admin, Users = members ?? new List <Database.POCO.User>() }; context.Groups.Add(group); context.SaveChanges(); return(CreateGroup(group)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebmailContext webmailContext) { webmailContext.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.Use(async(context, next) => { context.Request.EnableBuffering(); await next(); }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseAuditMiddleware(_ => _ .WithEventType("{verb}:{url}") .IncludeHeaders() .IncludeResponseHeaders() .IncludeRequestBody() .IncludeResponseBody()); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "Webmail"); }); }
public static Database.POCO.User CreateUser(WebmailContext context, string email, Role role = Role.USER, string firstName = "Mariusz", string lastName = "Tester") { var entity = new Database.POCO.User() { Email = email, FirstName = firstName, LastName = lastName, Role = role }; context.Users.Add(entity); context.SaveChanges(); return(entity); }
public static Database.POCO.User CreateTestUser(WebmailContext context, Role role = Role.USER, string email = "*****@*****.**") { var user = new Database.POCO.User() { Email = email, FirstName = "Mariusz", LastName = "Tester", Role = role }; context.Users.Add(user); context.SaveChanges(); return(user); }
public static void CreateNotification(WebmailContext context, Notification notification, NotificationType type) { var notificationEntity = new Database.POCO.Notification() { Content = notification.Content, ContentType = notification.ContentType, CreationTime = DateTime.Now, RecipientsList = context.Users.Where(u => notification.RecipientsList.Contains(u.Email)).ToList(), Type = type, WithAttachments = notification.WithAttachments }; context.Notifications.Add(notificationEntity); context.SaveChanges(); }
public static void CreateNotification(WebmailContext context, Notification notification, DateTime?creationTime = null, NotificationType type = NotificationType.API) { var time = creationTime ?? DateTime.Now; var entity = new Database.POCO.Notification() { Content = notification.Content, ContentType = notification.ContentType, WithAttachments = notification.WithAttachments, Type = type, CreationTime = time }; context.Notifications.Add(entity); context.SaveChanges(); }
public static Database.POCO.Message CreateMessage(WebmailContext context, string subject, string content, Database.POCO.User sender, List <Database.POCO.User> receivers, List <Database.POCO.User> cc, List <Database.POCO.User> bcc, DateTime?receivedTime = null) { var message = new Database.POCO.Message() { Sender = sender, Subject = subject, MessageBody = content, Attachments = new List <Database.POCO.Attachment>(), ReceivedTime = receivedTime ?? DateTime.Now }; message.MessagesReceivers = receivers.Select(mr => new MessagesReceivers() { User = mr, Message = message, IsRead = false }).ToList(); message.MessagesCCs = cc.Select(mc => new MessagesCCs() { User = mc, Message = message, IsRead = false }).ToList(); message.MessagesBCCs = bcc.Select(mb => new MessagesBCCs() { User = mb, Message = message, IsRead = false }).ToList(); message = context.Messages.Add(message).Entity; context.SaveChanges(); return(message); }
public HomeController(WebmailContext _context) { this.Context = _context; }
public static Database.POCO.User AuthorizeControllerUser(ControllerBase controller, WebmailContext context, Role role = Role.USER) { var testUser = CreateTestUser(context, role); var claims = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("emails", testUser.Email), }, "mock")); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = claims } }; return(testUser); }
public SqlGroupService(WebmailContext context) { this.context = context; }
public SqlUserService(WebmailContext context, IMessageService messageService) { this.context = context; this.messageService = messageService; }
public SqlMessageService(WebmailContext context) { this.context = context; }
public SqlNotificationService(WebmailContext context) { this.context = context; }
public SqlAttachmentService(WebmailContext context) { this.context = context; }