Beispiel #1
0
        public void DeleteForm(string keyValue)
        {
            var    id     = Convert.ToInt64(keyValue);
            Attach attach = attachRepository.Get(id);

            attach.DeletedMark  = true;
            attach.DeletionTime = DateTime.Now;
            attachRepository.Update(attach);
        }
Beispiel #2
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);
                }
            }
        }