Source

main / Source / WebClient / Web.Client / Controllers / RepositoryController.cs

Naethra D 3ee1b94 











































































using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataUp.Web.BizLogic;
using DataUp.Web.Client.ViewModel;
using BizLogicModel = DataUp.Web.BizLogic.Model;

namespace DataUp.Web.Client.Controllers
{
    /// <summary>
    /// Controller that provides functionality to access the Repository services.
    /// </summary>
    public class RepositoryController : Controller
    {
        private IRepositoryService repositoryService;

        public RepositoryController(IRepositoryService repositoryService)
        {
            this.repositoryService = repositoryService;
        }

        /// <summary>
        /// Gets the identifier from Repository.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <returns></returns>
        [HttpPost]
        public string GetIdentifier(IdentifierModel details)
        {
            string identifier = string.Empty;

            try
            {
                IdentifierDetail identifierDetail = new IdentifierDetail();

                identifierDetail.RepositoryName = details.RepositoryName;
                identifierDetail.Authorization = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(details.UserName + ":" + details.Password));
                identifierDetail.What = details.What;
                identifierDetail.Who = details.Who;

                DateTime whenDate;
                if (!DateTime.TryParse(details.When, out whenDate))
                {
                    whenDate = DateTime.UtcNow;
                    // Need to get created datetime
                }

                identifierDetail.When = whenDate;

                // Get Identifier.
                identifier = this.repositoryService.GetIdentifier(identifierDetail);
                BizLogicModel.User user = (BizLogicModel.User)Session["User"];
                var list = new List<BizLogicModel.Repository>();

                foreach (var val in user.RepositoryList)
                {
                    if (val.Name == details.RepositoryName)
                    {
                        val.AcceptUserAgreement = true;
                        val.UserName = details.UserName;
                    }
                    list.Add(val);
                }
                user.RepositoryList = list;
                Session["User"] = user;
            }
            catch (Exception ex)
            {
                return "false|" + ex.Message;
            }

            return identifier;
        }
    }
}