예제 #1
0
        public IActionResult Create([FromBody] CreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            if (model.AccessLevel != TemplateAccessLevel.Disabled &&
                model.AccessLevel != TemplateAccessLevel.Private &&
                model.AccessLevel != TemplateAccessLevel.Public)
            {
                return(JsonBadRequest("Invalid access level"));
            }

            var template = new Template
            {
                Name            = model.Name,
                Memo            = model.Memo,
                LatestVersion   = 0,
                AccessLevel     = model.AccessLevel,
                CreaterUserId   = CurrentUserInfo.Id,
                CreaterTenantId = CurrentUserInfo.SelectedTenant.Id,
            };

            templateRepository.Add(template);
            unitOfWork.Commit();
            return(JsonCreated(new IndexOutputModel(template)));
        }
예제 #2
0
        public async Task <bool> Handle(SaveTemplateCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var template             = request.ToModel();
            var templateAlreadyExist = await _templateRepository.Exist(template.Name);

            if (templateAlreadyExist)
            {
                await Bus.RaiseEvent(new DomainNotification("Template", "Template already exist."));

                return(false);
            }

            _templateRepository.Add(template);
            if (await Commit())
            {
                await Bus.RaiseEvent(new TemplateAddedEvent(template));

                return(true);
            }

            return(false);
        }
예제 #3
0
 public Int32 Create(TEMPLATE item, LOG log)
 {
     using (DbContextTransaction transaction = Db.Database.BeginTransaction(IsolationLevel.ReadCommitted))
     {
         try
         {
             _logRepository.Add(log);
             _baseRepository.Add(item);
             transaction.Commit();
             return(0);
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw ex;
         }
     }
 }
예제 #4
0
        public async Task <IActionResult> OnPost()
        {
            // TODO - Check if project exists

            Template.ProjectId = ProjectId;
            await _templateTbl.Add(Template);

            return(RedirectToPage("/Project/Details", new { id = Template.ProjectId }));
        }
 public async Task <bool> Add(User user, Template template)
 {
     try
     {
         template.fk_UserId = user.Id;
         return(_templateRepository.Add(template));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
예제 #6
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateTemplate request, CancellationToken cancellationToken)
        {
            var billingDate = _mapper.Map <Domain.Templates.BillingDate>(request.BillingDate);
            var timeZone    = _dateTimeZoneProvider[request.TimeZone];
            var template    = new Template(request.Name, request.Price, request.BillingModeId, billingDate, request.BillingPeriodMonth, request.BillingPeriodOffsetMonth, timeZone);

            _templateRepository.Add(template);
            await _templateRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            var vm = _mapper.Map <ViewTemplate>(template);

            return(CreatedAtAction(nameof(GetAsync), new { id = vm.Id }, vm));
        }
예제 #7
0
    public async Task <IActionResult> OnPostCreateTemplate()
    {
        // TODO: Error handling
        TemplateTbl result = await _templateTbl.Add(CreateTemplate).ConfigureAwait(false);

        await _projectTbl.UpdateFromQuery(x => x.Id.Equals(MarkAsActive.ProjectId), _ => new ProjectTbl
        {
            DateModified = DateTime.Now
        });

        TempData["toastStatus"]  = "success";
        TempData["toastMessage"] = $"Template created - {result.Name}";
        TempData["scrollToId"]   = $"template-{result.Id}";

        return(RedirectToPage("/Project/Details", new { id = CreateTemplate.ProjectId }));
    }
예제 #8
0
        public int Add(CreateTemplateRequest template)
        {
            if (!_folderManipulation.Exists(template.FolderId))
            {
                throw new NsiArgumentException(string.Format(TemplateManagementMessages.FolderInvalidId));
            }

            TemplateDomain templateDomain = new TemplateDomain
            {
                Name        = template.Name,
                FolderId    = template.FolderId,
                DateCreated = DateTime.Now
            };

            var result = _templateRepository.Add(templateDomain);

            if (result <= 0)
            {
                throw new NsiBaseException(string.Format(TemplateManagementMessages.TemplateCreationFailed));
            }

            TemplateVersionDomain templateVersionDomain = new TemplateVersionDomain
            {
                Code        = VERSION_CODE,
                TemplateId  = result,
                IsDefault   = true,
                DateCreated = templateDomain.DateCreated,
                Content     = JsonConvert.SerializeObject(template.Content)
            };
            var version = _templateVersionManipulation.Add(templateVersionDomain);

            if (version <= 0)
            {
                throw new NsiBaseException(string.Format(TemplateManagementMessages.TemplateCreationFailed));
            }

            return(result);
        }
 public bool SetTemplate(TemplateModel model)
 {
     try
     {
         if (model.TemplateID > 0)
         {
             var template = _templateRepository.GetById(model.TemplateID);
             if (template != null)
             {
                 template.TemplateName = model.TemplateName;
                 template.ModifiedBy   = 1;
                 template.ModifiedOn   = DateTime.UtcNow;
                 _templateRepository.Update(template);
             }
         }
         else
         {
             var template = new Template
             {
                 TemplateName = model.TemplateName,
                 CreatedBy    = 1,
                 CreatedOn    = DateTime.Now
             };
             _templateRepository.Add(template);
         }
         //_templateRepository.SaveChangesAsync();
         return(true);
     }
     catch (EntryPointNotFoundException ex)
     {
         return(false);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
예제 #10
0
        /// <summary>
        /// Загрузить новую версию шаблона
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loadBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = ".docx | *.docx";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            ofd.Multiselect = false;

            if (File.Exists(ofd.FileName) && templateTypesCB.SelectedItem is TemplateType)
            {
                byte[] fileBytes;
                try
                {
                    fileBytes = File.ReadAllBytes(ofd.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Ошибка загрузки файла: {ex.Message}");
                    return;
                }

                TemplateFile file = new TemplateFile
                {
                    FileData     = fileBytes,
                    HashMd5      = Md5Helper.GetMd5Hash(fileBytes),
                    TemplateType = (templateTypesCB.SelectedItem as TemplateType),
                    WhoUpload    = GlobalSettings.LoginUser
                };

                _templateRepository.Add(file);
                RefreshTemplateData();
            }
        }
예제 #11
0
 public async Task <bool> Add(Template template)
 {
     return(await _templateRepository.Add(template));
 }
예제 #12
0
 public void CreateTemplate(Template template)
 {
     templateRepository.Add(template);
 }