Ejemplo n.º 1
0
        public async Task <object> CreateSchedule(ScheduleDtoForImportExcel entity)
        {
            return(Ok(await _scheduleService.CreateSchedule(entity)));
            // if (await _ingredientService.CheckExists(entity.ID))
            //     return BadRequest("Ingredient ID already exists!");
            // if (await _ingredientService.CheckBarCodeExists(entity.Code))
            //     return BadRequest("Ingredient Barcode already exists!");
            // if (await _ingredientService.CheckExistsName(entity.Name))
            //     return BadRequest("Ingredient Name already exists!");
            // entity.CreatedDate = DateTime.Now.ToString("MMMM dd, yyyy HH:mm:ss tt");
            // if (await _ingredientService.Add1(entity))
            // {
            //     return NoContent();
            // }

            // throw new Exception("Creating the brand failed on save");
        }
Ejemplo n.º 2
0
        private async Task <ScheduleUpdateDto> AddSchedule(ScheduleDtoForImportExcel scheduleDto)
        {
            var result  = new ScheduleUpdateDto();
            var process = await _repoProcess.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(scheduleDto.Process.ToUpper()));

            if (process != null)
            {
                result.ProcessID = process.ID;
            }
            result.ModelName = scheduleDto.ModelName;
            result.ModelNo   = scheduleDto.ModelNo;
            result.ArticleNo = scheduleDto.ArticleNo;
            result.Treatment = scheduleDto.Process;

            result.Process = scheduleDto.Object;
            result.Part    = scheduleDto.Part;

            result.CreatedBy      = scheduleDto.CreatedBy;
            result.ProductionDate = scheduleDto.ProductionDate;

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <bool> CreateSchedule(ScheduleDtoForImportExcel obj)
        {
            try
            {
                var process = await _repoProcess.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(obj.Process.ToUpper()));

                var ProcessID = 0;
                if (process != null)
                {
                    ProcessID = process.ID;
                }
                var check = await _repoScheduleUpdate.FindAll().FirstOrDefaultAsync(y => y.ModelName.ToUpper().Equals(obj.ModelName.ToUpper()) && y.ModelNo.ToUpper().Equals(obj.ModelNo.ToUpper()) && y.ArticleNo.ToUpper().Equals(obj.ArticleNo.ToUpper()) && y.Treatment.ToUpper().Equals(obj.Process.ToUpper()) && y.Process.ToUpper().Equals(obj.Object.ToUpper()));

                if (check != null)
                {
                    var listCheck = await _repoPart.FindAll().Where(x => x.ScheduleID == check.ID).ToListAsync();

                    if (obj.listPart.Count == 0)
                    {
                        var checks = listCheck.Select(x => x.Name).Contains("Whole");
                        if (!listCheck.Select(x => x.Name).Contains("Whole"))
                        {
                            _repoPart.Add(new Part
                            {
                                Name       = "Whole",
                                ScheduleID = check.ID,
                                Status     = true
                            });
                            await _repoPart.SaveAll();
                        }
                        // var dataPart = new Part { Name = "Whole", ScheduleID = check.ID, Status = true };
                        // _repoPart.Add(dataPart);
                        // await _repoPart.SaveAll();
                    }
                    else
                    {
                        foreach (var part in obj.listPart)
                        {
                            if (!listCheck.Select(x => x.Name).Contains(part.value))
                            {
                                _repoPart.Add(new Part
                                {
                                    ScheduleID = check.ID,
                                    Name       = part.value,
                                });
                                await _repoPart.SaveAll();
                            }
                        }
                    }
                }
                if (check == null)
                {
                    // add schedule
                    var schedules = new SchedulesUpdate();

                    schedules.ModelName = obj.ModelName;
                    schedules.ModelNo   = obj.ModelNo;
                    schedules.ArticleNo = obj.ArticleNo;
                    schedules.Treatment = obj.Process;
                    schedules.Process   = obj.Object;

                    // schedules.a = x.Key.ArtProcessID;
                    schedules.CreatedBy  = obj.CreatedBy;
                    schedules.ApprovalBy = 0;
                    if (ProcessID == 1)
                    {
                        schedules.ProductionDate = obj.ProductionDate;
                        schedules.EstablishDate  = obj.ProductionDate.AddDays(-30);
                    }
                    else
                    {
                        schedules.ProductionDate = obj.ProductionDate;
                        schedules.EstablishDate  = obj.ProductionDate.AddDays(-15);
                    }
                    schedules.CreatedDate    = DateTime.Now;
                    schedules.UpdateTime     = DateTime.Now;
                    schedules.ApprovalStatus = false;
                    schedules.FinishedStatus = false;
                    _repoScheduleUpdate.Add(schedules);
                    await _repoScheduleUpdate.SaveAll();

                    // luu db xong moi add part

                    if (obj.listPart.Count == 0)
                    {
                        var dataPart = new Part {
                            Name = "Whole", ScheduleID = schedules.ID, Status = true
                        };
                        _repoPart.Add(dataPart);
                        await _repoPart.SaveAll();
                    }
                    else
                    {
                        foreach (var part in obj.listPart)
                        {
                            _repoPart.Add(new Part
                            {
                                ScheduleID = schedules.ID,
                                Name       = part.value,
                            });
                            await _repoPart.SaveAll();
                        }
                    }
                }
                return(true);
            }
            catch (System.Exception)
            {
                return(false);

                throw;
            }
        }