Example #1
0
        public Result SavePicture(HttpPostedFileBase httpPostedFile, int usesrId)
        {
            if (!_allowedExtentions.Any(httpPostedFile.FileName.Contains))
            {
                return new Result {
                           Message = "Only picture allowed.", Status = "Error"
                }
            }
            ;

            var name = _fileSystemPathService.GenerateUniqueFileName(httpPostedFile.FileName);

            var path       = _fileSystemPathService.GetImageSavePath() + name;
            var uploudfile = new UploadFile {
                Name = name, UserId = usesrId
            };
            var photo = _uploadFileRepository.SaveFile(uploudfile);

            try
            {
                httpPostedFile.SaveAs(path);
            }
            catch (Exception e)
            {
                _uploadFileRepository.DeleteFile(photo.Id);
                return(new Result {
                    Message = "Error: ." + e.Message, Status = "Error"
                });
            }

            return(new Result {
                Message = "Saved.", Status = "Success", Photo = photo
            });
        }
Example #2
0
        public async Task <PersonalModel> DeleteAsync(int id)
        {
            var model = await _repository.GetById(id);

            await _repository.DeleteAsync(id);

            _upload.DeleteFile(model.ProfileImage);
            return(model);
        }
Example #3
0
        public async Task <DocumentModel> DeleteAsync(int id)
        {
            var model = await _repository.GetById(id);

            await _repository.DeleteAsync(id);

            _upload.DeleteFile(model.path);

            return(model);
        }