Esempio n. 1
0
        public void EditCostPerRunStepBW(string codTaskExecutorOn, CostPerRunStepBW c)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    {
                        var taskEstimatedOn = taskExecutorRepository.GetSingleEstimatedOn(codTaskExecutorOn);
                        var taskExecutor = taskExecutorRepository.GetSingle(taskEstimatedOn.CodTaskExecutor);

                        //look for to=0 from=0
                        var chkStep = taskEstimatedOn.steps.OfType<CostPerRunStepBW>().FirstOrDefault(x => x.IdStep == c.IdStep);

                        c.TimeStampTable = DateTime.Now;

                        if (chkStep != null)
                        {
                            chkStep.FromUnit = c.FromUnit;
                            chkStep.ToUnit = c.ToUnit;
                            chkStep.CostPerUnit = c.CostPerUnit;
                            //new line!!!
                            taskExecutorRepository.EditSingleStep(chkStep);
                            taskExecutorRepository.Save();

                        }
                        else
                        {
                            taskEstimatedOn.steps.Add(c);
                        }

                        GenEmptyStep(taskExecutor);

                        taskExecutorRepository.Edit(taskExecutor);
                        taskExecutorRepository.Save();

                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message);
                }
            }

            //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name
            ViewBag.ActionMethod = "EditCostPerRunStepBW";
            //            return View("EditCostPerRunStep", c);
        }
Esempio n. 2
0
        //SAREBBE MEGLIO FARE IL POLIMORFISMO A SECONDA DEL TASKEXECUTOR
        private void GenEmptyStep(TaskExecutor taskExecutor)
        {
            taskExecutor = taskExecutorRepository.GetSingle(taskExecutor.CodTaskExecutor);

            foreach (var tskEst in taskExecutor.SetTaskExecutorEstimatedOn)
            {

                Step newStep;

                //look for to=0 from=0
                newStep = tskEst.steps.OfType<AvarageRunPerRunStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new AvarageRunPerRunStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }

                //look for to=0 from=0
                newStep = tskEst.steps.OfType<DeficitForWeightStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new DeficitForWeightStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }


                //look for to=0 from=0
                newStep = tskEst.steps.OfType<DeficitOnCostForWeightStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new DeficitOnCostForWeightStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }

                //look for to=0 from=0
                newStep = tskEst.steps.OfType<BindingAvarageRunPerRunStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new BindingAvarageRunPerRunStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }

                //look for to=0 from=0
                newStep = tskEst.steps.OfType<BindingCostPerRunStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new BindingCostPerRunStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }

                //look for to=0 from=0
                newStep = tskEst.steps.OfType<CostPerMqStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new CostPerMqStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }


                //look for to=0 from=0
                newStep = tskEst.steps.OfType<CostPerRunStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new CostPerRunStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }


                //look for to=0 from=0
                newStep = tskEst.steps.OfType<CostPerColorStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new CostPerColorStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }


                //look for to=0 from=0
                newStep = tskEst.steps.OfType<CostPerRunStepBW>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new CostPerRunStepBW();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }



                //look for to=0 from=0
                newStep = tskEst.steps.OfType<BindingAvarageRunPerRunStep>().FirstOrDefault(x => x.FromUnit == 9999999999 && x.ToUnit == 9999999999);

                if (newStep == null)
                {
                    newStep = new BindingAvarageRunPerRunStep();
                    newStep.FromUnit = 9999999999;
                    newStep.ToUnit = 9999999999;
                    newStep.CodTaskEstimatedOn = tskEst.CodTaskEstimatedOn;
                    newStep.TimeStampTable = DateTime.Now;
                    tskEst.steps.Add(newStep);
                }

            }

            taskExecutorRepository.Edit(taskExecutor);
            taskExecutorRepository.Save();

        }