コード例 #1
0
        public async Task <ActionResult <ResponseModel> > Create(StepCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Title.Trim().Length <= 0)
            {
                response.SetFailed("请输入步骤名称");
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (await _dbContext.DncRole.CountAsync(x => x.Name == model.Title) > 0)
                {
                    response.SetFailed("角色已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <StepCreateViewModel, WorkflowStep>(model);
                entity.UserList          = string.Join('|', model.UserList);
                entity.CreatedOn         = DateTime.Now;
                entity.Code              = RandomHelper.GetRandomizer(8, true, false, true, true);
                entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;

                await _dbContext.WorkflowStep.AddAsync(entity);

                await _dbContext.SaveChangesAsync();

                response.SetSuccess();
                return(Ok(response));
            }
        }
コード例 #2
0
 public StepModel(StepCreateViewModel step)
 {
     Name      = step.Name;
     Body      = step.Body;
     ArticleId = step.ArticleId;
     Date      = DateTime.Now;
 }
コード例 #3
0
ファイル: StepServiceTests.cs プロジェクト: Fanuer/HIS
        public async Task AddStep()
        {
            await InitializeAsync();

            using (var service = this.GetService())
            {
                var recipe = await this.DbContext.Recipes.Include(x => x.Steps).AsNoTracking().FirstAsync();

                var newStep = new StepCreateViewModel()
                {
                    Description = "new Step"
                };

                var result = await service.AddAsync(recipe.Id, newStep);

                Assert.NotEqual(0, result.Id);

                var recipeAfterAdding = await this.DbContext.Recipes.Include(x => x.Steps).AsNoTracking().FirstAsync(x => x.Id.Equals(recipe.Id));

                Assert.Equal(recipe.Steps.Count + 1, recipeAfterAdding.Steps.Count);

                var newCreatedStep = recipeAfterAdding.Steps.OrderBy(x => x.Order).Last();
                Assert.Equal(newStep.Description, newCreatedStep.Description);
            }
        }
コード例 #4
0
 public IActionResult CreateStep(StepCreateViewModel step)
 {
     _db.Steps.Add(new StepModel(step));
     _db.Articles.Find(step.ArticleId).Date = DateTime.Now;
     _db.SaveChanges();
     return(View(_db.Articles.Find(step.ArticleId)));
 }
コード例 #5
0
ファイル: RecipeStepService.cs プロジェクト: Fanuer/HIS
        public async Task <StepViewModel> AddAsync(int recipeId, StepCreateViewModel creationModel)
        {
            StepViewModel result = null;

            try
            {
                if (recipeId == default(int))
                {
                    throw new ArgumentNullException(nameof(recipeId), "RecipeId must be set");
                }
                if (creationModel == null)
                {
                    throw new ArgumentNullException(nameof(creationModel), "Data to create a step must be set");
                }

                if (creationModel.Order <= 0)
                {
                    var recipe = await this._recipeRep.FindAsync(recipeId, x => x.Steps);

                    if (recipe == null)
                    {
                        var message = $"No recipe with thie given id '{recipeId}' found";
                        this.Logger.LogError(String.Concat("Creating Step: ", message));
                        throw new DataObjectNotFoundException(message);
                    }
                    creationModel.Order = recipe.Steps.Count;
                    Logger.LogDebug($"No Order defined for new step. Set to max for recipe {recipe.Name}({recipe.Id})");
                }

                var dbModel = this.Mapper.Map <RecipeStep>(creationModel);
                dbModel.RecipeId = recipeId;
                var createdModel = await this.Repository.AddAsync(dbModel);

                result = Mapper.Map <StepViewModel>(createdModel);
                Logger.LogDebug($"New Step '{result.Id}' for recipe '{recipeId}' successfully created");
            }
            catch (Exception e)
            {
                var message = $"An Error occured while creating a new recipe step";
                Logger.LogError(new EventId(), e, message);
                throw new Exception(message);
            }

            return(result);
        }
コード例 #6
0
        public void Convert_StepCreateViewModel_To_RecipeStep()
        {
            Initialize();

            var input = new StepCreateViewModel()
            {
                Order       = 0,
                Description = "Test Description"
            };

            var output = Mapper.Map <RecipeStep>(input);

            Assert.Equal(0, output.Id);
            Assert.Equal(input.Description, output.Description);
            Assert.Equal(input.Order, output.Order);

            Assert.Equal(0, output.RecipeId);
            Assert.Null(output.Recipe);
        }
コード例 #7
0
        public async Task <ActionResult <ResponseModel> > Edit(StepCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (await _dbContext.WorkflowStep.
                    CountAsync(x => x.Title == model.Title && x.Code != model.Code) > 0)
                {
                    response.SetFailed("步骤已存在");
                    return(Ok(response));
                }

                var entity = await _dbContext.WorkflowStep.FindAsync(model.Code);

                entity.Title         = model.Title;
                entity.SortID        = model.SortID;
                entity.TemplateCode  = model.TemplateCode;
                entity.UserList      = string.Join('|', model.UserList);
                entity.Status        = model.Status;
                entity.IsCounterSign = model.IsCounterSign;


                entity.ModifiedOn         = DateTime.Now;
                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;

                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }
コード例 #8
0
 /// <summary>
 /// Creates a new Steps for a Recipe
 /// </summary>
 /// <param name="recipeId">Id of the owning recipe</param>
 /// <param name="newStep">Data of the new Step</param>
 /// <returns></returns>
 public async Task <StepViewModel> AddStepsAsync(int recipeId, StepCreateViewModel newStep)
 {
     return(await this.Client.PostAsJsonReturnAsync <StepCreateViewModel, StepViewModel>(newStep, $"Recipes/{recipeId}/Steps"));
 }
コード例 #9
0
        public async Task <IActionResult> CreateStepAsync(int recipeId, [FromBody] StepCreateViewModel model)
        {
            var result = await _service.AddAsync(recipeId, model);

            return(CreatedAtRoute("GetStepById", new { recipeId, id = result.Id }, result));
        }