示例#1
0
        public async Task <string> AddNewVersionOfMaterial(FilesDto dto)
        {
            if (_dbService.GetCountOfMaterials(dto.uploadedFile.FileName) == 0)
            {
                throw new MaterialNotInDbException("Material " + dto.uploadedFile.FileName +
                                                   " is not in the database.");
            }

            await _dbService.AddNewVersionOfMaterialToDb(dto, GenRandomNameInLocalStorage());

            return("New version of material" + dto.uploadedFile.FileName + " was upload");
        }
示例#2
0
文件: DbService.cs 项目: why-7/Matbox
 public async Task AddNewMaterialToDb(FilesDto dto, string nameInLocalStorage)
 {
     var path = "../Matbox.DAL/Files/" + nameInLocalStorage;
     await using (var fileStream = new FileStream(path, FileMode.Create))
     {
         await dto.uploadedFile.CopyToAsync(fileStream);
     }
     await _context.Materials.AddAsync(new Material { materialName = dto.uploadedFile.FileName, 
         category = dto.category, 
         metaDateTime = DateTime.Now, versionNumber = 1, 
         metaFileSize = dto.uploadedFile.Length, path = path }); 
     await _context.SaveChangesAsync();
 }
示例#3
0
        public async Task <int> Delete(FilesDto files)
        {
            string pathBuild = Path.Combine(Directory.GetCurrentDirectory(), "Uploads\\");

            if (files != null)
            {
                string[] fileName = files.Path.Split("Uploads/");
                pathBuild = Path.Combine(pathBuild, fileName[fileName.Length - 1]);
                DeleteFile(pathBuild);
                //if (File.Exists(Path.Combine(pathBuild)))
                // {
                //   File.Delete(pathBuild);
                // }
                return(await _filesRepository.DeleteById(files.Id));
            }
            return(1);
        }
示例#4
0
        public async Task <string> AddNewMaterial(FilesDto dto)
        {
            if (_dbService.GetCountOfMaterials(dto.uploadedFile.FileName) > 0)
            {
                throw new MaterialAlredyInDbException("Material " + dto.uploadedFile.FileName +
                                                      " is already in the database.");
            }

            if (Enum.IsDefined(typeof(Categories), dto.category) == false)
            {
                throw new WrongCategoryException("Wrong category. Use: Presentation, App, Other");
            }

            await _dbService.AddNewMaterialToDb(dto, GenRandomNameInLocalStorage());

            return("Material " + dto.uploadedFile.FileName + " was created");
        }
示例#5
0
        public ServiceResponse <FilesDto> Insert(FilesDto fileDto)
        {
            var file = new Files
            {
                FilesId  = fileDto.FilesId,
                FileName = fileDto.FileName
            };


            var response = new ServiceResponse <FilesDto>(null);

            try
            {
                _filesrepository.Insert(file);

                response.IsSuccessful = true;
            }
            catch (Exception e)
            {
                response.HasExceptionError = false;
                response.ExceptionMessage  = e.Message + " " + e.InnerException;
            }
            return(response);
        }
 public ServiceResponse <FilesDto> Update(FilesDto file)
 {
     return(_service.Update(file));
 }
 public ServiceResponse <FilesDto> Insert(FilesDto file)
 {
     return(_service.Insert(file));
 }
示例#8
0
            public async Task <PlanCompVM> Handle(UpdateLevTareaCommand request, CancellationToken cancellationToken)
            {
                PlanCompVM planVM      = new PlanCompVM();
                var        cabeceraDTO = IService.imgUpload(request.File);

                var correlativo = cabeceraDTO.correlativo;
                var descripcion = cabeceraDTO.descripcion;
                var estadoNew   = cabeceraDTO.estado;
                var porcentaje  = cabeceraDTO.porcentajeAvance;
                var fecha       = cabeceraDTO.fecha;

                var levTarea = _context.TLevantamientoPlan.FirstOrDefault(i => i.Correlativo == correlativo && i.Estado);

                levTarea.Descripcion      = descripcion;
                levTarea.Estado           = estadoNew;
                levTarea.PorcentajeAvance = porcentaje;
                levTarea.Fecha            = fecha;


                if (!estadoNew)
                {
                    List <TFile> fil = _context.TFile.Where(I => I.NroDocReferencia == correlativo.ToString() && I.Estado).ToList();

                    foreach (var item in fil)
                    {
                        item.Estado = false;
                        _context.TFile.Update(item);
                    }
                }
                _context.TLevantamientoPlan.Update(levTarea);
                await _context.SaveChangesAsync(cancellationToken);

                // Se muestra el resultado como si fuera GET
                var planAccionList = _context.TAccion.Include(i => i.RespPlanAccion).FirstOrDefault(i => i.CodAccion == levTarea.CodAccion && i.Estado);

                PlanRespVM plan = new PlanRespVM();

                plan.codAccion = planAccionList.CodAccion;


                ResponsablesDto planRespDto;

                foreach (var it in planAccionList.RespPlanAccion)
                {
                    if (it.Estado)
                    {
                        var datos = _context.TLevantamientoPlan.Where(i => i.CodAccion == it.CodAccion && i.CodPersona == it.CodPersona && i.Estado);
                        planRespDto                 = new ResponsablesDto();
                        planRespDto.codAccion       = it.CodAccion;
                        planRespDto.codPersona      = it.CodPersona;
                        planRespDto.porcentajeMayor = 0;
                        planRespDto.estado          = it.Estado;
                        if (datos.Count() > 0)
                        {
                            var max = datos.Max(i => i.PorcentajeAvance);
                            planRespDto.porcentajeMayor = max;
                        }
                        PersonaVM respVM = new PersonaVM();

                        if (!String.IsNullOrEmpty(it.CodPersona))
                        {
                            //respVM = await _persons.RequestNombApellidos(it.CodPersona);
                            respVM = await _mediator.Send(new GetPersonaQuery()
                            {
                                CodPersona = it.CodPersona
                            });
                        }
                        if (respVM != null)
                        {
                            planRespDto.nombres         = respVM.Nombres;
                            planRespDto.apellidoPaterno = respVM.ApellidoPaterno;
                            planRespDto.apellidoMaterno = respVM.ApellidoMaterno;
                        }
                        else
                        {
                            planRespDto.nombres         = "";
                            planRespDto.apellidoPaterno = "";
                            planRespDto.apellidoMaterno = "";
                        }

                        plan.RespPlanAccion.Add(planRespDto);
                    }
                }

                var sumaDiv = (plan.RespPlanAccion.Sum(i => i.porcentajeMayor) / plan.RespPlanAccion.Count());

                var accion = _context.TAccion.FirstOrDefault(i => i.CodAccion == levTarea.CodAccion && i.Estado);

                //double sumatoria = 0;
                if (sumaDiv > 0 && sumaDiv < 100)
                {
                    accion.CodEstadoAccion = "03";
                }

                else if (sumaDiv >= 100)
                {
                    accion.CodEstadoAccion = "02";
                }

                else
                {
                    accion.CodEstadoAccion = "01";
                }
                plan.codEstadoAccion = accion.CodEstadoAccion;

                _context.TAccion.Update(accion);
                await _context.SaveChangesAsync(cancellationToken);

                LevTareasFilesVM levTareasVM;
                var levs = _context.TLevantamientoPlan.Where(i => i.CodAccion == levTarea.CodAccion && i.Estado);

                List <String> codPersonas;
                List <TFile>  result;

                foreach (var item in levs)
                {
                    result      = new List <TFile>();
                    codPersonas = new List <String>();
                    codPersonas.Add(item.CodPersona);
                    //List<String> nombPerson = await _persons.Request(codPersonas);
                    List <String> nombPerson = await _mediator.Send(new GetCode2NameQuery()
                    {
                        data = codPersonas
                    });

                    levTareasVM                  = new LevTareasFilesVM();
                    levTareasVM.codAccion        = item.CodAccion;
                    levTareasVM.codPersona       = item.CodPersona;
                    levTareasVM.correlativo      = item.Correlativo;
                    levTareasVM.descripcion      = item.Descripcion;
                    levTareasVM.estado           = item.Estado;
                    levTareasVM.fecha            = item.Fecha;
                    levTareasVM.porcentajeAvance = item.PorcentajeAvance;
                    levTareasVM.nombres          = "";
                    if (nombPerson.Count != 0)
                    {
                        levTareasVM.nombres = nombPerson[0];
                    }
                    result = _context.TFile.Where(i => i.NroDocReferencia == item.Correlativo.ToString()).ToList();

                    FilesDto filesDto;

                    foreach (var it in result)
                    {
                        if (item.Estado == true)
                        {
                            filesDto = new FilesDto();

                            filesDto.size = it.ArchivoData.Length;
                            filesDto.correlativoArchivos = it.CorrelativoArchivos;
                            filesDto.descripcion         = it.Descripcion;
                            filesDto.grupoPertenece      = it.GrupoPertenece;
                            filesDto.nombre              = it.Nombre;
                            filesDto.nroDocReferencia    = it.NroDocReferencia;
                            filesDto.nroSubDocReferencia = it.NroSubDocReferencia;
                            filesDto.tipoArchivo         = it.TipoArchivo;
                            filesDto.estado              = it.Estado;
                            levTareasVM.files.Add(filesDto);
                        }
                    }
                    plan.registros.Add(levTareasVM);
                }
                plan.count = plan.registros.Count;
                planVM.plan.Add(plan);
                return(planVM);
            }
示例#9
0
 public Task ShareWorkFiles(string jobId, FilesDto files)
 => Put(new ExecuteParams($"/v2/jobs/{jobId}/files/sharedWorkFiles/share", files));