Пример #1
0
 public void Update(EwiFile entity)
 {
     _fileRepository.Update(entity);
 }
Пример #2
0
        public int Create(EwiFile entity)
        {
            _fileRepository.Insert(entity);

            return(entity.Id);
        }
Пример #3
0
 public void Delete(EwiFile entity)
 {
     entity.IsDeleted = true;
     _fileRepository.Update(entity);
 }
Пример #4
0
        public ActionResult UploadFile(int employeeId, int fileType)
        {
            foreach (string item in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
                if (file.ContentLength == 0)
                {
                    continue;
                }
                if (file.ContentLength > 0)
                {
                    try
                    {
                        string fileName   = file.FileName;
                        string uploadPath = string.Empty;

                        if (fileType == (int)FileType.EmployeeProfilePhoto)
                        {
                            uploadPath = Server.MapPath("~/Content/ProfilePhotos/");
                        }
                        else
                        {
                            uploadPath = "MediaFiles/";
                        }

                        if (!Directory.Exists(uploadPath))
                        {
                            Directory.CreateDirectory(uploadPath);
                        }

                        string guidFolder = Guid.NewGuid().ToString();
                        string path       = uploadPath + guidFolder;

                        Directory.CreateDirectory(path);

                        path = path + "/" + fileName;

                        file.SaveAs(path);

                        var now = DateTime.Now;

                        EwiFile newFile = new EwiFile()
                        {
                            ParentObjectId = employeeId,
                            FileName       = path,
                            FileType       = (FileType)fileType,
                            CreatedDate    = now,
                            UpdatedDate    = now,
                            ContentType    = file.ContentType
                        };

                        _fileService.Create(newFile);
                    }
                    catch (Exception e)
                    {
                        logger.Error(e, e.Message);
                    }
                }
            }

            return(Json(""));
        }