public void DatabaseUpdate(RecipeTemplate item)
 {
     using (var uow = new UnitOfWork(new AppDbContext()))
     {
         uow.RecipeTemplates.Update(item);
         uow.Commit();
     }
 }
 public void DomainUpdate(RecipeTemplate item)
 {
     //var edittarget = Items.SingleOrDefault(o => o.Id == item.Id);
     //edittarget.BatteryType = item.BatteryType;
     //edittarget.Name = item.Name;
     //edittarget.CycleCount = item.CycleCount;
     //edittarget.AssetUseCount = item.AssetUseCount;
     //edittarget.Records = item.Records;
 }
        private RecipeTemplate CreateRCRecipeTemplate(double chargeCurrent, double idleTime, double curr, RecipeTemplateServiceClass recipeTemplateService, StepTemplateServiceClass stepTemplateService)
        {
            try
            {
                //using (var uow = new UnitOfWork(new AppDbContext()))
                //{
                List <StepTemplate> stepTemplates = stepTemplateService.Items.ToList();
                var chargesteptemp = stepTemplates.SingleOrDefault(o => o.CurrentInput == chargeCurrent && o.CurrentUnit == CurrentUnitEnum.C && o.CutOffConditionValue == 1 && o.CutOffConditionType == CutOffConditionTypeEnum.CRate);
                if (chargesteptemp == null)
                {
                    chargesteptemp = CreateRCStepTemplate(chargeCurrent, CurrentUnitEnum.C, 1, CutOffConditionTypeEnum.CRate, stepTemplateService);
                    //new StepTemplate() { CurrentInput = chargeCurrent, CurrentUnit = CurrentUnitEnum.C, CutOffConditionValue = 1, CutOffConditionType = CutOffConditionTypeEnum.CRate };
                }

                var idlesteptemp = stepTemplates.SingleOrDefault(o => o.CurrentInput == 0 && o.CutOffConditionValue == idleTime && o.CutOffConditionType == CutOffConditionTypeEnum.Time_s);
                if (idlesteptemp == null)
                {
                    idlesteptemp = CreateRCStepTemplate(0, CurrentUnitEnum.mA, idleTime, CutOffConditionTypeEnum.Time_s, stepTemplateService);
                    //new StepTemplate() { CurrentInput = 0, CurrentUnit = CurrentUnitEnum.mA, CutOffConditionValue = idleTime, CutOffConditionType = CutOffConditionTypeEnum.Time_s };
                }

                var dsgsteptemp = stepTemplates.SingleOrDefault(o => o.CurrentInput == curr && o.CutOffConditionValue == 0);
                if (dsgsteptemp == null)
                {
                    dsgsteptemp = CreateRCStepTemplate(curr, CurrentUnitEnum.mA, 0, CutOffConditionTypeEnum.CRate, stepTemplateService);
                    //new StepTemplate() { CurrentInput = curr, CurrentUnit = CurrentUnitEnum.mA, CutOffConditionValue = 0, CutOffConditionType = CutOffConditionTypeEnum.CRate };
                }

                RecipeTemplate output;
                output = new RecipeTemplate()
                {
                    Name = $"{curr / -1000}A"
                };
                var step = new Step(chargesteptemp);
                output.Steps.Add(step);

                step = new Step(idlesteptemp);
                output.Steps.Add(step);

                step = new Step(dsgsteptemp);
                output.Steps.Add(step);

                step = new Step(idlesteptemp);
                output.Steps.Add(step);

                recipeTemplateService.SuperAdd(output);


                return(output);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Create RC RecipeTemplate Error!");
                return(null);
            }
        }
 internal void Abandon(RecipeTemplate recipeTemplate)
 {
     using (var uow = new UnitOfWork(new AppDbContext()))
     {
         RecipeTemplateGroup rtg = uow.RecipeTemplateGroups.SingleOrDefault(o => o.Name == "Abandoned");
         recipeTemplate.Group = rtg;
         uow.RecipeTemplates.Update(recipeTemplate);
         uow.Commit();
     }
 }
 public void DatabaseAdd(RecipeTemplate item)
 {
     using (var uow = new UnitOfWork(new AppDbContext()))
     {
         foreach (var step in item.Steps)
         {
             step.StepTemplate = uow.StepTemplates.GetById(step.StepTemplate.Id);
         }
         uow.RecipeTemplates.Insert(item);
         uow.Commit();
     }
 }
 internal void UpdateEditable(RecipeTemplate recipeTemplate)
 {
     recipeTemplate.Editable = false;
     SuperUpdate(recipeTemplate);
 }
 public void SuperUpdate(RecipeTemplate item)
 {
     DatabaseUpdate(item);
     DomainUpdate(item);
 }
 public void DomainAdd(RecipeTemplate item)
 {
     Items.Add(item);
 }
 public void SuperAdd(RecipeTemplate item)
 {
     DatabaseAdd(item);
     DomainAdd(item);
 }