| @@ -79,14 +79,14 @@ public sealed class MessageService : IMessageService | |||
| public async Task<MessageDto> GetById(int messageId) | |||
| { | |||
| var result = await _dbContext.Messages.AsNoTracking().FirstOrDefaultAsync(x => x.Id == messageId); | |||
| var result = await _dbContext.Messages.Include(x=>x.FileNames).AsNoTracking().FirstOrDefaultAsync(x => x.Id == messageId); | |||
| var mappedResult = _mapper.Map<MessageDto>(result); | |||
| return mappedResult; | |||
| } | |||
| public async Task<MessageDto> GetByCode(Guid code) | |||
| { | |||
| var result = await _dbContext.Messages.AsNoTracking().FirstOrDefaultAsync(x => x.Code == code.ToString()); | |||
| var result = await _dbContext.Messages.Include(x=>x.FileNames).AsNoTracking().FirstOrDefaultAsync(x => x.Code == code.ToString()); | |||
| var mappedResult = _mapper.Map<MessageDto>(result); | |||
| return mappedResult; | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using Microsoft.AspNetCore.Authorization; | |||
| using System.Text.Json; | |||
| using Microsoft.AspNetCore.Authorization; | |||
| using Microsoft.AspNetCore.Mvc; | |||
| using SecureSharing.Business.Dtos; | |||
| using SecureSharing.Business.Interfaces; | |||
| @@ -34,24 +35,28 @@ public sealed class HomeController : Controller | |||
| [HttpPost] | |||
| public async Task<IActionResult> CreateMessage(MessageModel model) | |||
| { | |||
| if (string.IsNullOrWhiteSpace(model.Text) && model.Files.Count == 0) | |||
| { | |||
| return Redirect("/"); | |||
| } | |||
| var message = new MessageDto { Text = model.Text }; | |||
| var currentPath = _webHostEnvironment.WebRootPath.Split('/')[0]; | |||
| // var filePath = $@"{currentPath}\{DefaultPath}\{message.Code}"; | |||
| var filePath = Path.Combine(currentPath, DefaultPath, message.Code.ToString()); | |||
| Directory.CreateDirectory(filePath); | |||
| // var basePath = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, message.Code.ToString()); | |||
| var basePath = $"C:\\Users\\radivoje.milutinovic\\Downloads\\fajlovitmp\\{message.Code}"; | |||
| Directory.CreateDirectory(basePath); | |||
| foreach (var formFile in model.Files) | |||
| { | |||
| if (formFile.Length > 0) | |||
| { | |||
| using var stream = new FileStream(filePath, FileMode.Create); | |||
| await formFile.CopyToAsync(stream); | |||
| message.FileNames.Add(new FileModel { Name = formFile.Name }); | |||
| } | |||
| if (formFile.Length <= 0) continue; | |||
| // Console.WriteLine(JsonSerializer.Serialize(formFile)); | |||
| var filePath = Path.Combine(basePath, formFile.FileName); | |||
| await using var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite); | |||
| await formFile.CopyToAsync(stream); | |||
| message.FileNames.Add(new FileModel { Name = formFile.FileName }); | |||
| } | |||
| var code = await _messageService.Create(message, model.ChosenPeriod); | |||
| return RedirectToAction("Link", "Home", new { code = code, share = true }); | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using SecureSharing.Business.Interfaces; | |||
| using SecureSharing.Data.Data; | |||
| using SecureSharing.Models; | |||
| namespace SecureSharing.Infrastructure; | |||
| @@ -23,7 +24,13 @@ public sealed class ModelFactory : IModelFactory | |||
| model = new LinkModel | |||
| { | |||
| MessageModel = new MessageModel { Code = code, Text = message.Text }, Share = share, | |||
| MessageModel = new MessageModel | |||
| { | |||
| Code = code, | |||
| Text = message.Text, | |||
| FileNames = message.FileNames.Select(x => x.Name).ToList() | |||
| }, | |||
| Share = share, | |||
| IsValid = message.IsValid | |||
| }; | |||
| @@ -9,6 +9,7 @@ public sealed class MessageModel | |||
| public Guid Code { get; set; } | |||
| public PeriodOfValidity ChosenPeriod { get; set; } | |||
| public List<IFormFile> Files { get; init; } = new(); | |||
| public List<string> FileNames { get; init; } = new(); | |||
| // public Dictionary<int, string> AvailablePeriods { get; set; } | |||
| } | |||
| @@ -11,7 +11,7 @@ | |||
| <label class="label-text">Sharing link avaliability</label> | |||
| <div class="button-box col-lg-12"> | |||
| <div class="single-button-input"> | |||
| <input id="OneTime" class="radio-input" type="radio" asp-for="ChosenPeriod" value="@PeriodOfValidity.ONE_TIME"> | |||
| <input id="OneTime" checked="checked" class="radio-input" type="radio" asp-for="ChosenPeriod" value="@PeriodOfValidity.ONE_TIME"> | |||
| <label for="OneTime" class="label-available"><span style="color:#FFA463">One</span> Time</label> | |||
| </div> | |||
| <div class="single-button-input"> | |||
| @@ -1,6 +1,7 @@ | |||
| @{ | |||
| Layout = "~/Views/Shared/_Layout.cshtml"; | |||
| } | |||
| @using Newtonsoft.Json | |||
| @model LinkModel | |||
| @@ -36,6 +37,18 @@ else | |||
| <div class="label-text link-show"> | |||
| @Model.MessageModel.Text | |||
| </div> | |||
| @if (Model.MessageModel.Files.Count > 0) | |||
| { | |||
| <div class="label-text"> | |||
| Files: | |||
| </div> | |||
| <div class="label-text link-show"> | |||
| @foreach (var file in Model.MessageModel.FileNames) | |||
| { | |||
| <p>@file</p> | |||
| } | |||
| </div> | |||
| } | |||
| } | |||
| else | |||
| { | |||
| @@ -63,14 +76,14 @@ else | |||
| </div> | |||
| } | |||
| </div> | |||
| <div class="label-text"> | |||
| Message: | |||
| </div> | |||
| <div class="label-text link-show"> | |||
| @Model.MessageModel.Text | |||
| </div> | |||
| <a class="btn btn-light share-button" asp-controller="Home" asp-action="Index">Share new message securely!</a> | |||
| } | |||
| } | |||
| @@ -135,6 +135,7 @@ body{ | |||
| .label-text { | |||
| font-size: 23px; | |||
| padding-left: 4px; | |||
| } | |||
| .label-text-lower{ | |||
| @@ -147,6 +148,7 @@ body{ | |||
| background-color: #90278F; | |||
| color: #FFFFFF; | |||
| } | |||
| .share-button { | |||
| /* Auto layout */ | |||