public async Task <Result <WindowDto> > SaveWindowAsync(WindowDto entity, bool forceNew = false) { if (entity.WindowId == Guid.Empty) { entity.WindowId = Guid.NewGuid(); return(await _repository.Notes.AddWindowAsync(entity)); } else { if (!forceNew) { return(await _repository.Notes.UpdateWindowAsync(entity)); } else { var checkExist = await GetWindowAsync(entity.NoteId, entity.UserId); if (checkExist.IsValid) { return(await _repository.Notes.UpdateWindowAsync(entity)); } else { return(await _repository.Notes.AddWindowAsync(entity)); } } } }
/// <summary> /// /// </summary> /// <param name="numberOfwindows"></param> /// <param name="maxWidth"></param> /// <param name="maxHeight"></param> /// <returns></returns> /// <remarks> /// Possibilmente facciamo in modo che il <paramref name="maxHeight"/> e <paramref name="maxWidth"/> non siano piu' grandi /// della risoluzione del Desktop. :) /// </remarks> public static List<WindowDto> Randomize(int numberOfwindows, int maxWidth, int maxHeight, IScreenResolution resolution) { var result = new List<WindowDto>(); for (int i = 1; i < numberOfwindows + 1; i++) { // Randomizziamo le dimensioni minime. var minWidthToRespect = rng.Next(maxWidth); var minHeightToRespect = rng.Next(maxHeight); var item = new WindowDto(); item.ID = i; item.Width = rng.Next(minWidthToRespect, maxWidth); item.MinWidth = minWidthToRespect; item.Height = rng.Next(minHeightToRespect, maxHeight); item.MinHeight = minHeightToRespect; // Definisci il posizionamento. item.X = rng.Next(1, resolution.Width - item.Width); item.Y = rng.Next(1, resolution.Height - item.Height); // Aggiungi al risultato. result.Add(item); } return result; }
/* -- For getting the windows --*/ internal static Window GetWindows(WindowDto window) { return(new Window { Win_Type = window.Win_Type, Win_Price = window.Win_Price, Win_Picture = window.Win_Picture }); }
/* Adding a window type */ public virtual void addWindow(WindowDto window) { try { db.Windows.Add(Helper.GetWindows(window)); db.SaveChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task Handle_WithDtoIdZero_ReturnEntityId(WindowDto dto, Window entity) { dto.Id = 0; dto.Finish = dto.Start.AddHours(2); this.mappingServiceMock.Setup(x => x.Map <Window>(It.IsAny <WindowDto>())).Returns(entity); var request = new SaveWindowCommand { EntityDto = dto }; var result = await this.handler.Handle(request, CancellationToken.None); Assert.AreEqual(entity.Id, result); }
private void Validate(WindowDto dto) { if (dto == null) { throw new ValidationException($"EntityDto of type {nameof(WindowDto)} is null in {nameof(SaveWindowCommandHandler)}"); } if (dto.Start.Date != dto.Finish.Date) { throw new ValidationException($"Start and finish dates should be the same"); } // ToDo: check if overlaps with existing shedule }
public async Task Handle_WithDtoIdZero_InsertsEntity(WindowDto dto, Window entity) { dto.Id = 0; dto.Finish = dto.Start.AddHours(2); this.mappingServiceMock.Setup(x => x.Map <Window>(It.IsAny <WindowDto>())).Returns(entity); var request = new SaveWindowCommand { EntityDto = dto }; var result = await this.handler.Handle(request, CancellationToken.None); this.repositoryMock.Verify(x => x.InsertAsync(entity)); this.repositoryMock.Verify(x => x.SaveChangesAsync()); }
public async Task Handle_WithDiffrentDates_ThrowsException(WindowDto dto) { var request = new SaveWindowCommand { EntityDto = dto }; dto.Start = DateTimeOffset.Now; dto.Finish = DateTimeOffset.Now.AddDays(2); var ex = Assert.ThrowsAsync <ValidationException>(async() => await this.handler.Handle(request, CancellationToken.None) ); Assert.That(ex.Message, Is.EqualTo("Start and finish dates should be the same")); }
public IActionResult AddWindows([FromBody] WindowDto window) { if (ModelState.IsValid) { try { repo.addWindow(window); return(Ok(string.Format("Successfull added Category {0}", window.Win_Type))); } catch (Exception e) { return(Ok(e.Message)); } } return(Ok("Failed try again")); }
public async Task Handle_WithDtoIdNotZero_UpdatesEntity(WindowDto dto, Window entity) { dto.Finish = dto.Start.AddHours(2); this.repositoryMock.Setup(x => x.FirstOrDefaultAsync(dto.Id)) .ReturnsAsync(entity); var request = new SaveWindowCommand { EntityDto = dto }; var result = await this.handler.Handle(request, CancellationToken.None); this.mappingServiceMock.Verify(x => x.Map <WindowDto, Window>(dto, entity)); this.repositoryMock.Verify(x => x.UpdateAsync(entity)); this.repositoryMock.Verify(x => x.SaveChangesAsync()); }
private async Task <bool> SaveFolderDto(IKntService service, Guid?userId, CarpetaExport carpetaExport, Guid?parent, List <EtiquetaExport> etiquetas) { string r11 = "\r\n"; string r12 = "\n"; string r21 = "&#x"; string r22 = "$$$"; int nErrors = 0; #region Import customization //// afumfer //// ....... //string r31 = @"D:\KaNote\Resources\ImgsEditorHtml"; //string r32 = @"D:\Anotas\Docs\__Imgs_!!ANTHtmlEditor!!_"; //string r41 = @"D:\KaNote\Resources\ImgsEditorHtml"; //string r42 = @"C:\Anotas\Docs\__Imgs_!!ANTHtmlEditor!!_"; //string r51 = @"_KNTERRORTRAP"; //string r52 = @"_ANTERRORTRAP"; //string r61 = @"_KNTERRORCODE"; //string r62 = @"_ANTERRORCODE"; //string r71 = @"_KNTERRORDESCRIPTION"; //string r72 = @"_ANTERRORDESCRIPTION"; //string r81 = ""; //string r82 = "[!ExecuteAnTScriptBGroundThread]"; //string r91 = ""; //string r92 = "_ANTForm.Exit();"; #endregion string r31 = @"KntResCon/"; string r32 = @"\\educacion.org\Almacen\Pincel\TareasTM\Doc\"; string r41 = @"KntResCon/"; string r42 = @"\\educacion.org\Almacen\Pincel\tareasTM\Doc\"; string r51 = @"KntResCon/"; string r52 = @"\\Educacion.org\Almacen\Pincel\TareasTM\Doc\"; var newFolderDto = new FolderDto { FolderNumber = carpetaExport.IdCarpeta, //FolderNumber = 0, Name = carpetaExport.NombreCarpeta, Order = carpetaExport.Orden, OrderNotes = carpetaExport.OrdenNotas, ParentId = parent }; var resNewFolder = await service.Folders.SaveAsync(newFolderDto); label1.Text = $"Added folder: {resNewFolder.Entity?.Name}"; label1.Refresh(); var folder = resNewFolder.Entity; foreach (var n in carpetaExport.Notas) { try { if (n.DescripcionNota.Contains(r12)) { // Hack multiples CR LF n.DescripcionNota = n.DescripcionNota.Replace(r12, r11); // Hack for problems in deserialization n.DescripcionNota = n.DescripcionNota.Replace(r22, r21); } #region Import customization //// afumfer //// ....... //// Hack inserted resources change n.DescripcionNota = n.DescripcionNota.Replace(r32, r31); n.DescripcionNota = n.DescripcionNota.Replace(r42, r41); n.DescripcionNota = n.DescripcionNota.Replace(r52, r51); //n.DescripcionNota = n.DescripcionNota.Replace(r62, r61); //n.DescripcionNota = n.DescripcionNota.Replace(r72, r71); //n.DescripcionNota = n.DescripcionNota.Replace(r82, r81); //n.DescripcionNota = n.DescripcionNota.Replace(r92, r91); #endregion (string descriptionNew, string scriptCode) = ExtractAnTScriptCode(n.DescripcionNota); DateTime fecMod; if (n.FechaModificacion > n.FechaHoraCreacion) { fecMod = n.FechaModificacion; } else { fecMod = n.FechaHoraCreacion; } var newNote = new NoteExtendedDto { FolderId = folder.FolderId, NoteNumber = n.IdNota, //NoteNumber = 0, Description = descriptionNew, Script = scriptCode, Topic = n.Asunto, CreationDateTime = n.FechaHoraCreacion, ModificationDateTime = fecMod, Tags = n.PalabrasClave, InternalTags = n.Vinculo, Priority = n.Prioridad }; if (!newNote.Tags.Contains("UC=")) { if ("afumfer fdomher jurivmar sesther sleoare dgoddelw".Contains(n.Usuario)) { if (!string.IsNullOrEmpty(newNote.Tags)) { newNote.Tags += "; "; } newNote.Tags += "UC=" + n.Usuario; } } // Add task if (n.FechaInicio > new DateTime(1901, 1, 1) || n.FechaResolucion > new DateTime(1901, 1, 1) || n.FechaPrevistaInicio > new DateTime(1901, 1, 1) || n.FechaPrevistaFin > new DateTime(1901, 1, 1) || n.Resuelto == true) { NoteTaskDto task = new NoteTaskDto { NoteId = Guid.Empty, UserId = (Guid)userId, CreationDateTime = n.FechaHoraCreacion, ModificationDateTime = fecMod, Description = newNote.Topic, Tags = "(ANotas import)", Priority = 1, Resolved = n.Resuelto, EstimatedTime = n.TiempoEstimado, SpentTime = n.TiempoInvertido, DifficultyLevel = n.NivelDificultad, ExpectedEndDate = n.FechaPrevistaFin, ExpectedStartDate = n.FechaPrevistaInicio, EndDate = n.FechaResolucion, StartDate = n.FechaInicio }; newNote.Tasks.Add(task); } // Add alarm if (n.Alarma > new DateTime(1901, 1, 1)) { var message = new KMessageDto { NoteId = Guid.Empty, UserId = userId, AlarmActivated = n.ActivarAlarma, ActionType = EnumActionType.UserAlarm, Comment = "(import ANotas)", AlarmDateTime = n.Alarma }; // Alarm type switch (n.TipoAlarma) { case 0: // estandar message.AlarmType = EnumAlarmType.Standard; break; case 1: // diaria message.AlarmType = EnumAlarmType.Daily; break; case 2: // semanal message.AlarmType = EnumAlarmType.Weekly; break; case 3: // mensual message.AlarmType = EnumAlarmType.Monthly; break; case 4: // anual message.AlarmType = EnumAlarmType.Annual; break; case 5: // cada hora message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60; break; case 6: // 4 horas message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60 * 4; break; case 7: // 8 horas message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60 * 8; break; case 8: // 12 diaria message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60 * 12; break; default: message.AlarmType = EnumAlarmType.Standard; break; } newNote.Messages.Add(message); } // Add resource if (!string.IsNullOrEmpty(n.NotaEx)) { #region Import resources for ContendInDB = true //// TODO: Refactor this line //var root = @"D:\ANotas\Docs"; //var fileFullName = $"{root}{n.NotaEx}"; //if (File.Exists(fileFullName)) //{ // var fileArrayBytes = File.ReadAllBytes(fileFullName); // var contentBase64 = Convert.ToBase64String(fileArrayBytes); // ResourceDto resource = new ResourceDto // { // NoteId = Guid.Empty, // ContentInDB = true, // Order = 1, // Container = service.RepositoryRef.ResourcesContainer + "\\" + DateTime.Now.Year.ToString(), // Name = $"{Guid.NewGuid()}_{Path.GetFileName(fileFullName)}", // Description = $"(ANotas import {n.NotaEx})", // ContentArrayBytes = fileArrayBytes, // ContentBase64 = contentBase64, // FileType = _store.ExtensionFileToFileType(Path.GetExtension(fileFullName)) // }; // newNote.Resources.Add(resource); //} #endregion #region Import resources for ContendInDB = false if (n.NotaEx[0] == '\\') { n.NotaEx = n.NotaEx.Substring(1); } string fileImport = Path.Combine(new[] { service.RepositoryRef.ResourcesContainerCacheRootPath, service.RepositoryRef.ResourcesContainer, n.NotaEx }); ResourceDto resource = new ResourceDto { NoteId = Guid.Empty, ContentInDB = false, Order = 1, Container = service.RepositoryRef.ResourcesContainer, Name = n.NotaEx, Description = $"(ANotas import {n.NotaEx})", ContentArrayBytes = null, ContentBase64 = null, FileType = _store.ExtensionFileToFileType(Path.GetExtension(fileImport)) }; newNote.Resources.Add(resource); #endregion } // Save note and PostIt Result <NoteExtendedDto> resNewNote = null; if (newNote.IsValid()) { resNewNote = await service.Notes.SaveExtendedAsync(newNote); label2.Text = $"Added note: {resNewNote.Entity?.Topic} - {resNewNote.Entity?.NoteId.ToString()}"; // Add Window WindowDto windowPostIt = new WindowDto { NoteId = resNewNote.Entity.NoteId, UserId = (Guid)userId, Visible = false, //n.Visible, AlwaysOnTop = n.SiempreArriba, PosX = n.PosX, PosY = n.PosY, Width = n.Ancho, Height = n.Alto, FontName = n.FontName, FontSize = n.FontSize, FontBold = n.FontBold, FontItalic = n.FontItalic, FontUnderline = n.FontUnderline, FontStrikethru = n.FontStrikethru, ForeColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ForeColor)), TitleColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ColorBanda)), TextTitleColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ForeColor)), NoteColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ColorNota)), TextNoteColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ForeColor)) }; var resNewPostIt = await service.Notes.SaveWindowAsync(windowPostIt); } else { label2.Text = $"Added note: ERROR invalid note."; var msgErr = newNote.GetErrorMessage(); MessageBox.Show($"ERROR invalid note: {msgErr}"); } label2.Refresh(); } catch (Exception ex) { // TODO: hack, hay un registro erróneo en la exportación. nErrors++; if (nErrors > 1) { MessageBox.Show($"Más de error. Error: {ex.Message}"); } //throw; } } // For each folder child all recursively to this method foreach (var c in carpetaExport.CarpetasHijas) { await SaveFolderDto(service, userId, c, folder.FolderId, etiquetas); } return(await Task.FromResult <bool>(true)); }
public async Task <int> Post([FromBody] WindowDto window) { return(await this.mediator.Send(new SaveCommand <WindowDto>(window))); }