Source

main / Source / WebService / Web.Admin / Controllers / HomeController.cs

Naethra D ba1cb57 























































































































































































using System;
using System.Linq;
using System.Web.Mvc;
using DataUp.Web.Admin.DataLayer;
using DataUp.Web.Admin.ViewModel;
using DataUp.Web.Common;

namespace DataUp.Web.Admin.Controllers
{
    public class HomeController : Controller
    {
        IRepositoryDetailsDB repositoryDetails;

        public HomeController(IRepositoryDetailsDB repositoryDb)
        {
            this.repositoryDetails = repositoryDb;
        }

        [Authorize]
        public ActionResult Index()
        {
            var list = repositoryDetails.GetRespositories();
            var types = repositoryDetails.GetRespositoryTypes();
            var values = new RepositoryListViewModel()
            {
                RepositoriesList =
                               (from val in list.ToList()
                                select new RepositoryViewModel()
                                {
                                    RepositoryId = val.Id,
                                    RepositoryName = val.RepositoryName,
                                    RepositoryType = val.RepositoryType.RepositoryType1,
                                    IdentifierUrl = val.GetIdentifierUrl,
                                    PostFileUrl = val.PostFileUrl,
                                    UserName = val.UserId,
                                    Password = String.IsNullOrEmpty(val.Password) ? "" : StringExtensions.DecodeFrom64(val.Password),
                                    RepositoryTypes = new SelectList(types, "RepositoryTypeId", "RepositoryType1"),
                                    SelectedRepositoryTypeId = val.RepositoryType.RepositoryTypeId.ToString(),
                                    UserAgreement = val.UserAgreement,
                                    PasswordRequired = val.RepositoryType.PasswordRequired.HasValue ? val.RepositoryType.PasswordRequired.Value : false,
                                    CreatedBy = val.AdminUser.UserName
                                }).ToList()
            };

            return View(values);
        }

        [Authorize]
        public ActionResult Delete(string repositoryId)
        {

            if (repositoryDetails.DeleteRepositoryDetails(Convert.ToInt32(repositoryId)))
            {
                var list = repositoryDetails.GetRespositories();
                var types = repositoryDetails.GetRespositoryTypes();
                var values = new RepositoryListViewModel()
                {
                    RepositoriesList =
                                   (from val in list.ToList()
                                    select new RepositoryViewModel()
                                    {
                                        RepositoryId = val.Id,
                                        RepositoryName = val.RepositoryName,
                                        RepositoryType = val.RepositoryType.RepositoryType1,
                                        IdentifierUrl = val.GetIdentifierUrl,
                                        PostFileUrl = val.PostFileUrl,
                                        UserName = val.UserId,
                                        Password = String.IsNullOrEmpty(val.Password) ? "" : StringExtensions.DecodeFrom64(val.Password),
                                        RepositoryTypes = new SelectList(types, "RepositoryTypeId", "RepositoryType1"),
                                        SelectedRepositoryTypeId = val.RepositoryType.RepositoryTypeId.ToString(),
                                        UserAgreement = val.UserAgreement,
                                        PasswordRequired = val.RepositoryType.PasswordRequired.HasValue ? val.RepositoryType.PasswordRequired.Value : false,
                                        CreatedBy = val.AdminUser.UserName
                                    }).ToList()
                };

                return View("_RepositoryList", values);
            }
            else
            {
                return RedirectToAction("General", "Error", new { errorMessage = "Error while deleting" });
            }

        }

        [Authorize]
        public ActionResult Add(RepositoryViewModel repository)
        {
            if (repositoryDetails.AddRepository(new RepositoryDetail()
            {
                Id = repository.RepositoryId,
                RepositoryName = repository.RepositoryName,
                RepositoryTypeId = Convert.ToInt16(repository.SelectedRepositoryTypeId),
                GetIdentifierUrl = repository.IdentifierUrl,
                PostFileUrl = repository.PostFileUrl,
                UserId = repository.UserName,
                UserAgreement = repository.UserAgreement,
                Password = String.IsNullOrEmpty(repository.Password) ? "" : StringExtensions.EncodeTo64(repository.Password),
                CreatedBy = Helper.GetLoggedInUserID()
            }))
            {
                var list = repositoryDetails.GetRespositories();
                var types = repositoryDetails.GetRespositoryTypes();
                var values = new RepositoryListViewModel()
                {
                    RepositoriesList =
                                   (from val in list.ToList()
                                    select new RepositoryViewModel()
                                    {
                                        RepositoryId = val.Id,
                                        RepositoryName = val.RepositoryName,
                                        RepositoryType = val.RepositoryType.RepositoryType1,
                                        IdentifierUrl = val.GetIdentifierUrl,
                                        PostFileUrl = val.PostFileUrl,
                                        UserName = val.UserId,
                                        Password = String.IsNullOrEmpty(val.Password) ? "" : StringExtensions.DecodeFrom64(val.Password),
                                        RepositoryTypes = new SelectList(types, "RepositoryTypeId", "RepositoryType1"),
                                        SelectedRepositoryTypeId = val.RepositoryType.RepositoryTypeId.ToString(),
                                        UserAgreement = val.UserAgreement,
                                        PasswordRequired = val.RepositoryType.PasswordRequired.HasValue ? val.RepositoryType.PasswordRequired.Value : false,
                                        CreatedBy = val.AdminUser.UserName
                                    }).ToList()
                };

                return View("_RepositoryList", values);
            }
            else
            {
                return RedirectToAction("General", "Error", new { errorMessage = "Error while adding" });
            }
        }

        [Authorize]
        public ActionResult Get(string repositoryId)
        {
            var value = repositoryDetails.GetRepositoryDetails(Convert.ToInt32(repositoryId));
            var types = repositoryDetails.GetRespositoryTypes();
            RepositoryViewModel model = new RepositoryViewModel();
            model.RepositoryTypes = new SelectList(types, "RepositoryTypeId", "RepositoryType1");
            if (value != null)
            {
                model.RepositoryId = value.Id;
                model.RepositoryName = value.RepositoryName;
                model.SelectedRepositoryTypeId = value.RepositoryTypeId.ToString();
                model.IdentifierUrl = value.GetIdentifierUrl;
                model.PostFileUrl = value.PostFileUrl;
                model.UserName = value.UserId;
                model.UserAgreement = value.UserAgreement;
                model.Password = String.IsNullOrEmpty(value.Password) ? "" : StringExtensions.DecodeFrom64(value.Password);
                model.PasswordRequired = value.RepositoryType.PasswordRequired.HasValue ? value.RepositoryType.PasswordRequired.Value : false;
                model.CreatedBy = value.AdminUser.UserName;
            }

            return View("_Edit", model);
        }

        [Authorize]
        [HttpPost]
        public JsonResult GetTypes()
        {
            var types = repositoryDetails.GetRespositoryTypes();
            if (null != types)
            {
                var values = from val in types.ToList()
                             select new { TypeId = val.RepositoryTypeId, TypeName = val.RepositoryType1, Required = val.PasswordRequired };

                return Json(values);
            }

            return Json(new { TypeId = "0", TypeName = "", Required = "" });
        }

        [Authorize]
        [HttpPost]
        public bool Validate(string repositoryName, string repositoryId, string repositoryTypeId)
        {
            bool isValid = false;
            isValid = !repositoryDetails.CheckRepositoryName(repositoryName,
                                                        Convert.ToInt32(repositoryId),
                                                        Convert.ToInt32(repositoryTypeId));

            return isValid;
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.