public async Task <ActionResult> AddStatus(int id, [FromBody] RFQActionDTO actionDto)
    {
        var item = _context.RFQs
                   .Where(o => o.RFQId == id)
                   .Include(r => r.RFQActions)
                   .ThenInclude(a => a.Representative)
                   .Include(r => r.RFQActions)
                   .ThenInclude(a => a.RFQActionAtts)
                   .FirstOrDefault();

        if (item == null)
        {
            return(NotFound());
        }

        actionDto.ActionCode     = DateTime.Now.Ticks.ToString();
        actionDto.ActionTime     = DateTime.Now;
        actionDto.SubmissionTime = DateTime.Now;

        var action = _mapper.Map <RFQAction>(actionDto);

        item.RFQActions.Add(action);
        _context.SaveChanges();

        // var retAction = new
        // {
        //     actionDto.ActionCode,
        //     actionDto.ActionTime,
        //     actionDto.ActionType,
        //     actionDto.Comments,
        //     actionDto.Id,
        //     actionDto.RepresentativeId,
        //     Representative = new
        //     {
        //         actionDto.Representative?.Address,
        //         actionDto.Representative?.Continuous,
        //         actionDto.Representative?.Created,
        //         actionDto.Representative?.DateOfBirth,
        //         actionDto.Representative?.Id,
        //         actionDto.Representative?.Name,
        //         actionDto.Representative?.PersonalPhone,
        //         actionDto.Representative?.Phone,
        //         actionDto.Representative?.Position,
        //         actionDto.Representative?.UniversalIP
        //     },
        //     RFQActionAtts = actionDto.RFQActionAtts?.Select(att => new
        //     {
        //         att.FileName,
        //         att.FileUrl,
        //         att.FileType,
        //         att.Value
        //     }),
        //     actionDto.RFQId,
        //     actionDto.SubmissionTime,
        //     actionDto.UniversalIP
        // };

        actionDto = _mapper.Map <RFQActionDTO>(action);
        return(await Task.Run(() => new ObjectResult(actionDto)));
    }
    public async Task <ActionResult> UpdateStatus(int id, int actionId, [FromBody] RFQActionDTO actionDto)
    {
        var item = _context.RFQs
                   .Where(o => o.RFQId == id)
                   .Include(r => r.RFQActions)
                   .ThenInclude(a => a.RFQActionAtts)
                   .FirstOrDefault();

        if (item == null)
        {
            return(await Task.Run(() => NotFound()));
        }

        var orgAction = item.RFQActions.Where(a => a.Id == actionId).FirstOrDefault();

        if (orgAction == null)
        {
            return(await Task.Run(() => NotFound()));
        }

        orgAction = _mapper.Map(actionDto, orgAction);
        _mapper.Map(actionDto, orgAction, opt =>
        {
            opt.ConfigureMap().ForMember(tgt => tgt.Representative, op => op.Ignore());
        });
        // orgAction.ActionType = actionDto.ActionType;
        // orgAction.RepresentativeId = actionDto.RepresentativeId;
        // orgAction.Comments = actionDto.Comments;
        // orgAction.UniversalIP = actionDto.UniversalIP;

        foreach (var att in orgAction.RFQActionAtts.Reverse())
        {
            if (actionDto.RFQActionAtts.Count(at => actionId == att.RFQActionId && at.FileName == att.FileName) == 0)
            {
                orgAction.RFQActionAtts.Remove(att);
            }
        }

        foreach (var att in orgAction.RFQActionAtts)
        {
            if (orgAction.RFQActionAtts.Count(at => at.RFQActionId == actionId && at.FileName == att.FileName) == 0)
            {
                // if (System.IO.Directory.Exists())
                // {

                // }
                string url = AppDomain.CurrentDomain.BaseDirectory + $"wwwroot\\Att\\{ id }\\{ actionId }" + att.FileName;
                // att.FileUrl = url;
                // System.IO.File.WriteAllBytes(url, Convert.FromBase64String(att.Value));
                orgAction.RFQActionAtts.Add(att);
            }
        }

        orgAction.SubmissionTime = DateTime.Now;
        _context.SaveChanges();

        // var retAction = new
        // {
        //     actionDto.ActionCode,
        //     actionDto.ActionTime,
        //     actionDto.ActionType,
        //     actionDto.Comments,
        //     actionDto.Id,
        //     actionDto.RepresentativeId,
        //     Representative = new
        //     {
        //         actionDto.Representative.Address,
        //         actionDto.Representative.Continuous,
        //         actionDto.Representative.Created,
        //         actionDto.Representative.DateOfBirth,
        //         actionDto.Representative.Id,
        //         actionDto.Representative.Name,
        //         actionDto.Representative.PersonalPhone,
        //         actionDto.Representative.Phone,
        //         actionDto.Representative.Position,
        //         actionDto.Representative.UniversalIP
        //     },
        //     RFQActionAtts = actionDto.RFQActionAtts?.Select(att => new
        //     {
        //         att.FileName,
        //         att.FileUrl,
        //         att.FileType,
        //         att.Value
        //     }),
        //     actionDto.RFQId,
        //     actionDto.SubmissionTime,
        //     actionDto.UniversalIP
        // };

        return(await Task.Run(() => new ObjectResult(actionDto)));
    }