/// <summary> /// Adds an attachment /// </summary> /// <param name="attachment"></param> /// <returns></returns> public int AddAttachment(AttachmentDomain attachment) { ValidationHelper.NotNull(attachment, NotificationMessages.AttachmentNotProvided); ValidationHelper.NotNull(attachment.File, NotificationMessages.AttachmentFileNotProvided); return(_attachmentRepository.Add(attachment)); }
/// <summary> /// Add a new attachment /// </summary> /// <param name="attachment"></param> /// <returns></returns> public int Add(AttachmentDomain attachment) { var attachmentDb = new Attachment().FromDomainModel(attachment); _context.Attachment.Add(attachmentDb); _context.SaveChanges(); return(attachmentDb.AttachmentId); }
public static AttachmentDto MapToDtoModel(this AttachmentDomain att) { return(new AttachmentDto { Name = att.Name, SizeMb = att.SizeMb }); }
/// <summary> /// Delete attachment with id /// </summary> /// <param name="attachmentId"></param> public void DeleteAttachmentById(int attachmentId) { AttachmentDomain attachmentDomain = _attachmentRepository.GetById(attachmentId); if (attachmentDomain == null) { throw new NsiArgumentException(NotificationMessages.AttachmentWithIdDoesNotExist); } _attachmentRepository.DeleteById(attachmentId); }
public static Attachment FromDomainModel(this Attachment obj, AttachmentDomain domain) { if (obj == null) { obj = new Attachment(); } obj.AttachmentId = domain.Id; obj.File = domain.File; obj.DateCreated = DateTime.Now; return(obj); }
public IHttpActionResult Add(AddAttachmentRequest request) { request.ValidateNotNull(); // convert from request model to domain model var attachmentDomain = new AttachmentDomain() { File = request.File }; return(Ok(new AddAttachmentResponse() { Data = _attachmentManipulation.AddAttachment(attachmentDomain), Success = Common.Enumerations.ResponseStatus.Succeeded })); }