Exemplo n.º 1
0
        public async Task <int> UpdateStep(int aStepId, StepModel aStepModel)
        {
            var theStepEntityToChange = await Context.Step.SingleOrDefaultAsync(i => i.StepId == aStepId);

            if (theStepEntityToChange == null)
            {
                throw new NullReferenceException("There is currently no Step with that Id in the database.");
            }

            var theNewStepEntity = aStepModel.ToEntity();

            Context.Update(theStepEntityToChange);
            await Context.SaveChangesAsync();

            return(theStepEntityToChange.StepId);
        }
Exemplo n.º 2
0
        //CREATE
        public async Task <StepModel> CreateStep(StepModel aStepModel)
        {
            if (aStepModel == null)
            {
                throw new NullReferenceException("No step model was given.");
            }

            var theLastStepIdUsed = await Context.Step.MaxAsync(i => i.StepId);

            aStepModel.StepId = theLastStepIdUsed + 1;

            var theStepEntity = aStepModel.ToEntity();

            Context.Step.Add(theStepEntity);
            await Context.SaveChangesAsync();

            return(aStepModel);
        }