Esempio n. 1
0
        public bool UpdateTransferTask(TransferTask updateTask)
        {
            var taskService = new TaskService();

            task task = taskService.FindByTaskNumber(updateTask.TaskNumber);

            if (task == null)
            {
                return false;
            }

            task.StartTime = updateTask.StartTime;
            task.EndTime = updateTask.EndTime;
            task.Memo = updateTask.Memo;

            new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber);

            var pigService = new PigService();

            List<long> pigList =
                (from taskDetail in updateTask.TransferFrom
                 from pig in taskDetail.Pig.Split(',')
                 select pigService.FindByNumber(pig).Id).ToList();

            int oldLen = task.task_pig.Count;
            int newLen = pigList.Count;
            int leastLength = oldLen < newLen ? oldLen : newLen;

            for (int i = 0; i < leastLength; i++)
            {
                task.task_pig.ElementAt(i).PigId = pigList[i];
            }

            var transferTaskPigService = new TaskPigService();

            for (int i = leastLength; i < oldLen; i++)
            {
                transferTaskPigService.Delete(transferTaskPigService.Find(task.task_pig.ElementAt(i).Id));
            }

            for (int i = leastLength; i < newLen; i++)
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigList[i]
                                      });
            }

            var pigstyService = new PigstyService();

            List<long> pigstyList = (from taskDetail in updateTask.TransferTo
                                     from pigsty in taskDetail.Pigsty.Split(',')
                                     select
                                         pigstyService.FindByNumber(int.Parse(pigsty)).First(
                                             m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList();

            oldLen = task.task_pigsty.Count;
            newLen = pigstyList.Count;
            leastLength = oldLen < newLen ? oldLen : newLen;

            for (int i = 0; i < leastLength; i++)
            {
                task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i];
            }

            var taskPigstyService = new TaskPigstyService();

            for (int i = leastLength; i < oldLen; i++)
            {
                taskPigstyService.Delete(taskPigstyService.Find(task.task_pigsty.ElementAt(i).Id));
            }

            for (int i = leastLength; i < newLen; i++)
            {
                task.task_pigsty.Add(new task_pigsty
                                         {
                                             PigstyId = pigstyList[i]
                                         });
            }

            taskService.Update(task);

            return true;
        }
        public bool UpdatePreventionDiseaseTask(PreventionDiseaseTask updateTask)
        {
            var taskService = new TaskService();

            task task = taskService.FindByTaskNumber(updateTask.TaskNumber);

            if (task == null)
            {
                return false;
            }

            task.StartTime = updateTask.StartTime;
            task.EndTime = updateTask.EndTime;
            task.Memo = updateTask.Memo;

            if (task.task_prevention.FirstOrDefault() == null)
            {
                task.task_prevention.Add(new task_prevention
                                             {
                                                 PreventionTypeId = long.Parse(updateTask.DiseaseName)
                                             });
            }
            else
            {
                task.task_prevention.First().PreventionTypeId = long.Parse(updateTask.DiseaseName);
            }

            new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber);

            var pigstyService = new PigstyService();

            List<long> pigstyList = (from taskDetail in updateTask.Taskdetails
                                     from pigsty in taskDetail.Pigsty.Split(',')
                                     select
                                         pigstyService.FindByNumber(int.Parse(pigsty)).First(
                                             m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList();

            int oldLen = task.task_pigsty.Count;
            int newLen = pigstyList.Count;
            int leastLength = oldLen < newLen ? oldLen : newLen;

            for (int i = 0; i < leastLength; i++)
            {
                task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i];
            }

            var taskPigstyService = new TaskPigstyService();

            for (int i = leastLength; i < oldLen; i++)
            {
                taskPigstyService.Delete(taskPigstyService.Find(task.task_pigsty.ElementAt(i).Id));
            }

            for (int i = leastLength; i < newLen; i++)
            {
                task.task_pigsty.Add(new task_pigsty
                                         {
                                             PigstyId = pigstyList[i]
                                         });
            }

            taskService.Update(task);

            return true;
        }