Source

main / Source / WebClient / Web.Client / Extensions / PostFileDetailExtensions.cs

Full commit
using System;
using System.Linq;
using DataUp.Web.BizLogic;
using DataUp.Web.Client.ViewModel;

namespace DataUp.Web.Client
{
    /// <summary>
    /// Extension for the PostFileDetail object which represents the file to be posted to repository.
    /// </summary>
    public static class PostFileDetailExtensions
    {
        public static void SetValuesFrom(this PostFileDetail postfileDetail, DocumentDetailViewModel documentDetail)
        {
            DateTime date = new DateTime();
            DateTime.TryParse(documentDetail.MetadataList.Where(m => m.Label.ToLowerInvariant().Contains("today's date")).FirstOrDefault().Value, out date);

            postfileDetail.RepositoryName = documentDetail.SelectedRepositoryId;
            postfileDetail.Authorization = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(documentDetail.UserName + ":" + documentDetail.Password));
            postfileDetail.What = documentDetail.Citation.Title;
            postfileDetail.Who = documentDetail.Citation.Publisher;
            postfileDetail.When = date;
            postfileDetail.Identifier = documentDetail.Citation.Identifier;
            postfileDetail.Id = documentDetail.DocumentId;
            postfileDetail.IsCompressed = !documentDetail.IsPostAsXSL;
            postfileDetail.FileName = documentDetail.DocumentName;
        }
    }
}