Ejemplo n.º 1
0
        public FactorDto Add(FactorDto factorDto)
        {
            Factor factor = new Factor
            {
                FactorDateTime   = factorDto.DateFa.ConvertToDateTime(),
                RegisterDateTime = DateTime.Now,
                DateFa           = factorDto.DateFa,

                Time                  = factorDto.Time,
                Comment               = factorDto.Comment,
                CustomerId            = factorDto.CustomerId,
                EngineVolumeId        = factorDto.EngineVolumeId,
                UserAssistantId       = factorDto.UserAssistantId,
                UserExpertId          = factorDto.UserExpertId,
                UserOperatorId        = factorDto.UserOperatorId,
                UserTechnicianId      = factorDto.UserTechnicianId,
                AirConditionerModelId = factorDto.AirConditionerModelId,
            };

            try
            {
                _dbContext.Factors.Add(factor);
                _dbContext.SaveChanges();

                var factorEntity = _dbContext.Factors.Find(factor.Id);
                factorEntity.Code = GetCode(factor);

                _dbContext.SaveChanges();

                if (factorDto.FactorPieceDtos != null)
                {
                    factorDto.FactorPieceDtos.ForEach(e =>
                    {
                        e.FactorId = factor.Id;
                    });
                    _factorPieceService.Add(factorDto.FactorPieceDtos);
                }

                if (factorDto.FactorWorkDtos != null)
                {
                    factorDto.FactorWorkDtos.ForEach(e =>
                    {
                        e.FactorId = factor.Id;
                    });
                    _factorWorkService.Add(factorDto.FactorWorkDtos);
                }

                return(GetById(factor.Id));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public IActionResult Add(FactorDto factorDto)
        {
            var factor = _factorService.Add(factorDto);


            var facorJson = Newtonsoft.Json.JsonConvert.SerializeObject(factor);

            TempData["factorNew"] = facorJson;


            return(RedirectToAction("DisplayFactorCode"));
        }