Esempio n. 1
0
 public ActionResult <RequestProcessingResult> UploadFile([FromForm] NewWorkRequest request)
 {
     return(Ok(workFile.RequestProcessing(request)));
 }
Esempio n. 2
0
        public RequestProcessingResult RequestProcessing(NewWorkRequest request)
        {
            var result      = new RequestProcessingResult();
            var newWorkData = new NewWorkData();

            newWorkData.ProjectID = request.ProjectID;

            foreach (var file in request.Files)
            {
                var document = GetXDocument(file, result);

                if (document != null && NoExistsFile(file.FileName, result))
                {
                    // создание нового Work
                    var workId = Guid.NewGuid();
                    var work   = new WorkDto()
                    {
                        ID           = workId,
                        ProjectID    = request.ProjectID,
                        Name         = file.FileName,
                        UploadDate   = DateTime.Now.ToString(),
                        ModifiedDate = DateTime.Now.ToString(),
                        Validated    = false,
                        Data         = document.ToString().Replace("'", "''")
                    };

                    newWorkData.Works.Add(work);

                    var sources      = newWorkData.Sources;
                    var countSources = sources?.Count() == null ? 0 : sources.Count();
                    var transUnits   = document.GetTransUnits();

                    foreach (var transUnit in transUnits)
                    {
                        var clearTarget = transUnit.Target.ReplaceSpace();
                        if (countSources == 0)
                        {
                            var sourceid = Guid.NewGuid();
                            newWorkData.Sources.Add(new SourceDto()
                            {
                                ID        = sourceid,
                                LocalID   = transUnit.LocalID,
                                ProjectID = request.ProjectID,
                                Text      = transUnit.Source
                            });
                            newWorkData.Targets.Add(new TargetDto()
                            {
                                SourceID  = sourceid,
                                WorkID    = workId,
                                Text      = clearTarget,
                                Validated = false
                            });
                        }
                        else if (countSources > 0)
                        {
                            var source = newWorkData.Sources.FirstOrDefault(s => s.Text == transUnit.Source && s.LocalID == transUnit.LocalID);
                            if (source != null)
                            {
                                newWorkData.Targets.Add(new TargetDto()
                                {
                                    SourceID  = source.ID,
                                    WorkID    = workId,
                                    Text      = clearTarget,
                                    Validated = false
                                });
                            }
                        }
                    }
                    result.FilesAdded.Add(file.FileName);
                }
            }
            InsertEntities(newWorkData);
            return(result);
        }