public bool Upload(FileUploadModel file) { var status = database.Statuses.Get(x => x.Title == "Closed").Result; var user = database.Users.Get(x => x.IdenityId == file.UserId).Result; if (user == null) { throw new UserServiceException("User wasn't found"); } var ex = System.IO.Path.GetExtension(file.File.FileName); var type = database.Types.Get(x => x.Format == ex).Result; if (type == null) { type = new DAL.Models.CommonModels.Type { Format = ex }; } var path = FileManagment.GeneratePath(file); var file_tosave = new File() { Status = status, Description = file.Description, User = user, Name = file.Name, Type = type, Path = new DAL.Models.CommonModels.Path() { Link = path.Path } }; database.Files.Create(file_tosave); database.Save(); return(true); }