예제 #1
0
        //public List<AreaGridDto> GetList()
        //{
        //    var specification = new Specification<Area>(u => u.DeletedMark == false);
        //    var sortingOtopns = new SortingOptions<Area, int?>(x => x.SortCode, isDescending: false);
        //    var list = areaRepository.FindAll(specification, sortingOtopns).ToList();
        //    return Mapper.Map<List<AreaGridDto>>(list);
        //}

        //public AreaOutputDto GetForm(string keyValue)
        //{
        //    var id = Convert.ToInt64(keyValue);
        //    AreaOutputDto areaOutputDto = new AreaOutputDto();
        //    Area area = areaRepository.Get(id);
        //    AutoMapper.Mapper.Map<Area, AreaOutputDto>(area, areaOutputDto);
        //    return areaOutputDto;
        //}

        public void SubmitForm(AttachInputDto attachInputDto, string keyValue)
        {
            Attach attach = new Attach();

            if (!string.IsNullOrEmpty(keyValue))
            {
                //var id = Convert.ToInt64(keyValue);
                //area = areaRepository.Get(id);
                //AutoMapper.Mapper.Map<AreaInputDto, Area>(areaInputDto, area);
                //area.LastModificationTime = DateTime.Now;
                //areaRepository.Update(area);
            }
            else
            {
                try
                {
                    AutoMapper.Mapper.Map <AttachInputDto, Attach>(attachInputDto, attach);
                    attach.Id            = IdWorkerHelper.GenId64();
                    attach.CreationTime  = DateTime.Now;
                    attach.CreatorUserId = 1;
                    attachRepository.Add(attach);
                }
                catch
                {
                    AutoMapper.Mapper.Map <AttachInputDto, Attach>(attachInputDto, attach);
                    attach.Id            = IdWorkerHelper.GenId64();
                    attach.CreationTime  = DateTime.Now;
                    attach.CreatorUserId = 1;
                    attachRepository.Add(attach);
                }
            }
        }
예제 #2
0
        public Guid CreateNew(LoadFileModel model)
        {
            if (!model.FileName.ToLowerInvariant().EndsWith(".xml"))
            {
                model.FileName += ".xml";
            }

            var user = _userSvc.CurrentUser();

            Repos.File file          = _files.GetByIdUserAndLabel(user.Id, model.FileName);
            var        encriptionKey = model.FileKey;

            var crys  = new CryptoService();
            var empty = crys.Empty;
            var root  = crys.Initialize(empty);

            var strData   = crys.Save();
            var encrypted = Encoding.UTF8.GetBytes(_crypt.Encrypt(strData, encriptionKey));

            if (file == null)
            {
                file = new Repos.File
                {
                    Id      = Guid.NewGuid(),
                    Label   = model.FileLabel,
                    Name    = model.FileName,
                    UserId  = user.Id,
                    Content = encrypted
                };
                _files.Add(file);
            }
            else
            {
                file.Content = encrypted;
                _files.Update(file);
            }
            _attach.DeleteFile(file.Id);
            foreach (var singleFile in root.Attachments)
            {
                //_attach.DeleteFile(Guid.Parse(singleFile.Id));
                var toAdd = new Attach
                {
                    Id     = Guid.Parse(singleFile.Id),
                    UserId = user.Id,
                    FileId = file.Id,
                    Name   = file.Name,
                    Data   = singleFile.Data
                };
                _attach.Add(toAdd);
            }
            return(file.Id);
        }
예제 #3
0
        public Guid Upload(String itemId)
        {
            var    user = _userSvc.CurrentUser();
            Attach file = _attach.GetById(Guid.Parse(itemId));

            if (file != null && file.UserId != user.Id)
            {
                throw new Exception();
            }
            if (HttpContext.Current.Request.Files["file"] == null)
            {
                throw new Exception();
            }
            var encriptionKey = HttpContext.Current.Session["FILEKEY"].ToString();

            using (var fileUploadStream = HttpContext.Current.Request.Files["file"].InputStream)
            {
                using (var ms = new MemoryStream())
                {
                    fileUploadStream.CopyTo(ms);
                    var data = ms.ToArray();

                    var strData = Encoding.UTF8.GetString(data);


                    var      cry = (CryptoService)HttpContext.Current.Session["DATA"];
                    AuthLeaf ida = cry.FindById(itemId) as AuthLeaf;
                    ida.HasAttachment = HttpContext.Current.Request.Files["file"].FileName;

                    var id = _files.GetIdByIdUserAndLabel(user.Id, HttpContext.Current.Session["FILE"].ToString());

                    var encrypted = _crypt.Encrypt(data, encriptionKey);
                    if (file == null)
                    {
                        file = new Attach
                        {
                            Id     = Guid.Parse(itemId),
                            Data   = encrypted,
                            FileId = id,
                            Name   = HttpContext.Current.Request.Files["file"].FileName,
                            UserId = user.Id
                        };
                        _attach.Add(file);
                    }
                    else
                    {
                        file.Data = encrypted;
                        file.Name = HttpContext.Current.Request.Files["file"].FileName;
                        _attach.Update(file);
                    }
                    Save();


                    return(file.Id);
                }
            }
        }
예제 #4
0
        public void SubmitForm(AttachInputDto attachInputDto, string keyValue)
        {
            Attach attach = new Attach();

            if (!string.IsNullOrEmpty(keyValue))
            {
                //var id = Convert.ToInt64(keyValue);
                //area = areaRepository.Get(id);
                //AutoMapper.Mapper.Map<AreaInputDto, Area>(areaInputDto, area);
                //area.LastModificationTime = DateTime.Now;
                //areaRepository.Update(area);
            }
            else
            {
                AutoMapper.Mapper.Map <AttachInputDto, Attach>(attachInputDto, attach);
                long UserId = Convert.ToInt64(OperatorProvider.Provider.GetCurrent().Id);
                attach.Id            = IdWorkerHelper.GenId64();
                attach.DeletedMark   = false;
                attach.CreationTime  = DateTime.Now;
                attach.CreatorUserId = UserId;
                attachRepository.Add(attach);
            }
        }