Source

main / Source / WebService / Web.Admin.DataLayer / RepositoryDetailsDB.cs

Full commit
Naethra D ba1cb57 











































































































































using System;
using System.Collections.Generic;
using System.Linq;

namespace DataUp.Web.Admin.DataLayer
{
    public class RepositoryDetailsDB : RepositoryBase<RepositoryDetail>, IRepositoryDetailsDB
    {
        public RepositoryDetailsDB(DCXLAdminEntities dcxlEntities)
            : base(dcxlEntities) { }


        public IEnumerable<RepositoryDetail> GetRespositories()
        {
            IEnumerable<RepositoryDetail> repositories = from val in this.DCXLDbContext.RepositoryDetails
                                               .Include("RepositoryType")
                                               .Include("AdminUser")
                                                         select val;

            if (repositories == null)
            {
                repositories = new List<RepositoryDetail>();
            }

            return repositories;
        }

        public RepositoryDetail GetRepositoryDetails(int repositoryId)
        {
            return
                this.DCXLDbContext.RepositoryDetails.FirstOrDefault(q => q.Id == repositoryId && q.IsActive == true);
        }

        public bool CheckRepositoryName(string repositoryName, int repositoryId, int repositoryTypeId)
        {
            if (repositoryTypeId == 0)
            {
                return this.DCXLDbContext.RepositoryDetails.Any(q => q.RepositoryName == repositoryName.Trim());
                //this.DCXLDbContext.RepositoryDetails.Any(q => q.RepositoryName == repositoryName && q.RepositoryTypeId == repositoryTypeId );
            }
            else
            {
                return this.DCXLDbContext.RepositoryDetails.Any(q => q.Id != repositoryId && q.RepositoryName == repositoryName.Trim());
                // this.DCXLDbContext.RepositoryDetails.Any(q => q.Id != repositoryId && q.RepositoryName == repositoryName && q.RepositoryTypeId == repositoryTypeId);
            }
        }

        public IEnumerable<RepositoryType> GetRespositoryTypes()
        {
            return from val in this.DCXLDbContext.RepositoryTypes
                   select val;
        }

        public bool AddRepository(RepositoryDetail value)
        {
            bool isSuccess = false;
            try
            {
                var repository = this.DCXLDbContext.RepositoryDetails.FirstOrDefault(q => q.Id == value.Id);
                if (repository != null && value.Id > 0)
                {
                    isSuccess = UpdateRepositoryDetails(value);
                }
                else
                {
                    RepositoryDetail repositoryDetail = new RepositoryDetail();
                    repositoryDetail.RepositoryName = value.RepositoryName;
                    repositoryDetail.GetIdentifierUrl = value.GetIdentifierUrl;
                    repositoryDetail.PostFileUrl = value.PostFileUrl;
                    repositoryDetail.UserAgreement = value.UserAgreement;
                    repositoryDetail.UserId = value.UserId;
                    repositoryDetail.Password = value.Password;
                    repositoryDetail.RepositoryTypeId = value.RepositoryTypeId;
                    repositoryDetail.IsActive = true;
                    repositoryDetail.CreatedBy = value.CreatedBy;
                    this.DCXLDbContext.RepositoryDetails.AddObject(repositoryDetail);
                    this.DCXLDbContext.SaveChanges();
                    isSuccess = true;
                }

            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return isSuccess;
        }

        public bool UpdateRepositoryDetails(RepositoryDetail value)
        {
            bool isSuccess = false;
            try
            {
                var repository = this.DCXLDbContext.RepositoryDetails.FirstOrDefault(q => q.Id == value.Id);
                if (repository != null)
                {
                    repository.RepositoryTypeId = value.RepositoryTypeId;
                    repository.RepositoryName = value.RepositoryName;
                    repository.GetIdentifierUrl = value.GetIdentifierUrl;
                    repository.PostFileUrl = value.PostFileUrl;
                    repository.UserId = value.UserId;
                    repository.Password = value.Password;
                    repository.UserAgreement = value.UserAgreement;

                    this.DCXLDbContext.SaveChanges();
                    isSuccess = true;
                }
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return isSuccess;
        }

        public bool DeleteRepositoryDetails(int repositoryId)
        {
            bool isSuccess = false;
            try
            {
                var repository = this.DCXLDbContext.RepositoryDetails.FirstOrDefault(q => q.Id == repositoryId);
                if (repository != null)
                {
                    this.DCXLDbContext.RepositoryDetails.DeleteObject(repository);
                }

                this.DCXLDbContext.SaveChanges();
                isSuccess = true;
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return isSuccess;
        }

    }
}