Exemplo n.º 1
0
        private void CreateClauseTemplate(int sectionId, Clause clause, int userId)
        {
            // Setup clause
            var licenseClause = new LicenseClause
            {
                LicenseSectionID = sectionId,
                CreatedAt        = GetDate,
                CreatedBy        = userId,
                OrderNumber      = clause.OrderNumber
            };

            // Save clause
            _clauses.Add(licenseClause);

            // Setup clause template
            var clauseTemplate = new LicenseClauseTemplate
            {
                Description     = clause.Description,
                LegalText       = clause.LegalText,
                ShortText       = clause.ShortText,
                CreatedAt       = GetDate,
                CreatedBy       = userId,
                Status          = (int)TemplateStatus.Draft,
                LicenseClauseID = licenseClause.ID,
                ClauseType      = (int)GetTypeForClause(clause.LegalText),
                Version         = 1
            };

            // Save clause template
            _clauseTemplates.Add(clauseTemplate);
        }
Exemplo n.º 2
0
        public void CreateClauseTemplate(int sectionId, LicenseClauseTemplateModel model, LoggedInUserDetails user)
        {
            // Check whether user is not admin
            if (!user.IsSysAdmin)
            {
                throw new BaseException("Access denied.");
            }

            // Get clauses for section
            var clauses = _clauses.Where(p => p.LicenseSectionID == sectionId).ToList();

            // Setup available order position
            var lastOrderNumber = 0;

            if (clauses.Any())
            {
                lastOrderNumber = clauses.Max(p => p.OrderNumber);
            }

            // Setup license clause
            var licenseClause = new LicenseClause
            {
                LicenseSectionID = model.LicenseSectionId,
                CreatedAt        = GetDate,
                CreatedBy        = user.ID.Value,
                OrderNumber      = lastOrderNumber + 1
            };

            // Save license clause
            _clauses.Add(licenseClause);

            // Setup clause template
            var clauseTemplate = new LicenseClauseTemplate
            {
                CreatedAt       = GetDate,
                CreatedBy       = user.ID.Value,
                Description     = model.Description,
                LegalText       = model.LegalText,
                LicenseClauseID = licenseClause.ID,
                ClauseType      = (int)GetTypeForClause(model.LegalText),
                ShortText       = model.ShortText,
                Status          = (int)TemplateStatus.Draft,
                Version         = 1
            };

            // Save clause template
            _clauseTemplates.Add(clauseTemplate);
        }
        public static ClauseModel ToModel(this LicenseClauseTemplate template, int sectionId)
        {
            var result = new ClauseModel();

            result.ClauseId         = template.LicenseClauseID;
            result.ClauseTemplateId = template.ID;
            result.LegalText        = template.LegalText;
            result.SectionId        = sectionId;
            result.Type             = template.ClauseType;

            if ((ClauseType)result.Type == ClauseType.InputAndDropDown)
            {
                result.SetupDropDownItems();
            }

            return(result);
        }
        public static LicenseClauseTemplateModel ToModel(this LicenseClauseTemplate model)
        {
            // Setup result
            var result = new LicenseClauseTemplateModel();

            result.ID          = model.ID;
            result.ShortText   = model.ShortText;
            result.Description = model.Description;
            result.LegalText   = model.LegalText;
            result.Version     = model.Version;
            result.Status      = (TemplateStatus)model.Status;
            result.CreatedAt   = model.CreatedAt;
            result.UpdatedAt   = model.UpdatedAt;

            // Return result
            return(result);
        }
Exemplo n.º 5
0
        public void Init()
        {
            var today = DateTime.Now;

            userSysAdmin = new User
            {
                ID             = 2,
                OrganizationID = 1,
                IsActive       = true,
                Email          = "*****@*****.**",
                IsSysAdmin     = true,
            };

            user = new User
            {
                ID             = 3,
                IsActive       = true,
                Email          = "*****@*****.**",
                IsSysAdmin     = false,
                OrganizationID = null,
            };

            sectionA = new LicenseSection
            {
                ID        = 1,
                CreatedBy = user.ID,
                Title     = "sectionA"
            };

            sectionB = new LicenseSection
            {
                ID        = 2,
                CreatedBy = user.ID,
                Title     = "sectionB"
            };

            sectionC = new LicenseSection
            {
                ID        = 3,
                CreatedBy = user.ID,
                Title     = "sectionC"
            };

            licenseTemplate = new LicenseTemplate
            {
                ID        = 1,
                CreatedAt = today,
                CreatedBy = 1,
                Status    = (int)TemplateStatus.Active,
                Name      = "titleLicense"
            };

            clauseTemplateDraft = new LicenseClauseTemplate
            {
                ID              = 1,
                Status          = (int)TemplateStatus.Draft,
                Description     = "Descr",
                LegalText       = "text",
                ShortText       = "shortText",
                LicenseClauseID = 1,
                Version         = 1
            };

            clauseTemplateActive = new LicenseClauseTemplate
            {
                ID          = 2,
                Status      = (int)TemplateStatus.Active,
                Description = "Descr",
                LegalText   = "text",
                ShortText   = "shortText",
                Version     = 1
            };

            clause1SectionA = new LicenseClause
            {
                ID               = 1,
                OrderNumber      = 0,
                LicenseSectionID = sectionA.ID
            };

            clause2SectionA = new LicenseClause
            {
                ID               = 2,
                OrderNumber      = 0,
                LicenseSectionID = sectionA.ID
            };

            clause1SectionB = new LicenseClause
            {
                ID               = 3,
                OrderNumber      = 0,
                LicenseSectionID = sectionA.ID
            };

            var fileMock = new Mock <HttpPostedFileBase>();

            _clauseService          = new Mock <ILicenseClauseService>();
            _clauseTemplateService  = new Mock <ILicenseClauseTemplateService>();
            _sectionService         = new Mock <ILicenseSectionService>();
            organizationService     = new Mock <IOrganizationService>();
            userService             = new Mock <IUserService>();
            licenseTemplateService  = new Mock <ILicenseTemplatesService>();
            userNotificationService = new Mock <IUserNotificationService>();
            notificationService     = new Mock <INotificationService>();
            // Setup notification service
            notificationService.SetupGet(m => m.User).Returns(userNotificationService.Object);
            var urlHelper = new Mock <UrlHelper>();

            context = new Mock <ControllerContext>();
            context.Setup(m => m.HttpContext.Request.Files.Count).Returns(1);
            context.Setup(m => m.HttpContext.Request.Files[0]).Returns(fileMock.Object);

            _sectionService.Setup(m => m.GetAll()).Returns(new List <LicenseSection> {
                sectionA, sectionB, sectionC
            });
            _sectionService.Setup(m => m.Get(sectionA.ID)).Returns(sectionA);
            _sectionService.Setup(m => m.Get(sectionB.ID)).Returns(sectionB);
            _sectionService.Setup(m => m.Get(sectionC.ID)).Returns(sectionC);

            _clauseService.Setup(m => m.Get(It.IsAny <Expression <Func <LicenseClause, bool> > >()))
            .Returns(new List <LicenseClause> {
                clause1SectionA, clause2SectionA
            });
            _clauseService.Setup(i => i.Get(clause1SectionA.ID)).Returns(clause1SectionA);

            _clauseTemplateService.Setup(m => m.Get(It.IsAny <Expression <Func <LicenseClauseTemplate, bool> > >()))
            .Returns(new List <LicenseClauseTemplate> {
                clauseTemplateDraft
            });
            _clauseTemplateService.Setup(m => m.Get(clauseTemplateDraft.ID)).Returns(clauseTemplateDraft);
            _clauseTemplateService.Setup(m => m.Get(clauseTemplateActive.ID)).Returns(clauseTemplateActive);

            licenseTemplateService.Setup(m => m.GetPublishedGlobalLicense()).Returns(licenseTemplate);

            controller = new LicenseClausesController(_clauseService.Object, _sectionService.Object,
                                                      _clauseTemplateService.Object, userService.Object, organizationService.Object,
                                                      licenseTemplateService.Object, notificationService.Object)
            {
                LoggedInUser      = new LoggedInUserDetails(userSysAdmin),
                Url               = urlHelper.Object,
                ControllerContext = context.Object
            };
        }