public SlotWithAttachment AddAttachment(AttachmentReference attachmentReference, AttachmentSlot slot) { if (AttachmentsBySlot == null) { AttachmentsBySlot = new List <SlotWithAttachment>(); } else if (AttachmentsBySlot.Any(x => x.SlotId == slot.Id && x.Attachment != null)) { log.Dump( LogLevel.Error, new { slot, attachmentReference }, "Slot is not free"); throw new ApplicationException(string.Format("Slot `{0}` is not free", slot.Id)); } else { AttachmentsBySlot.RemoveAll(x => x.Attachment == null); } var added = new SlotWithAttachment() { Date = DateTime.Now, Attachment = attachmentReference, SlotId = slot.Id }; AttachmentsBySlot.Add(added); return(added); }
private void MoveToSlot(Employee employee, string attachmentId) { if (employee.AttachmentsBySlot == null) { employee.AttachmentsBySlot = new List<SlotWithAttachment>(); } var note = employee.Notes.Where(x => x.Attachment != null && x.Attachment.Id == attachmentId).First(); var slot = employee.AttachmentsBySlot.Where(x => x.SlotId == SlotId).FirstOrDefault(); if (slot == null) { slot = new SlotWithAttachment() { SlotId = SlotId }; employee.AttachmentsBySlot.Add(slot); } if (slot.Attachment == null) { slot.Date = note.RegisterDate; slot.Attachment = note.Attachment; if (string.IsNullOrWhiteSpace(note.Note) || note.Note == DownNoteText) { employee.Notes.Remove(note); } else { note.Attachment = null; } } }
public SlotWithAttachment AddAttachment(AttachmentReference attachmentReference, AttachmentSlot slot) { if (AttachmentsBySlot == null) { AttachmentsBySlot = new List<SlotWithAttachment>(); } else if (AttachmentsBySlot.Any(x => x.SlotId == slot.Id && x.Attachment != null)) { log.Dump( LogLevel.Error, new { slot, attachmentReference }, "Slot is not free"); throw new ApplicationException(string.Format("Slot `{0}` is not free", slot.Id)); } else { AttachmentsBySlot.RemoveAll(x => x.Attachment == null); } var added = new SlotWithAttachment() { Date = DateTime.Now, Attachment = attachmentReference, SlotId = slot.Id }; AttachmentsBySlot.Add(added); return added; }